Search code examples
jsxadobe-illustratorextendscript

How do I save a selection programmatically?


In Adobe Illustrator I can select something on the Artboard and then go to Selection > Save Selection and give it a name. That stored selection is also stored in the .ai file and can be selected when reopening the file.

Is the same possible with using ExtendScript?

So far I only found a way to select everything with app.activeDocument.selectObjectsOnActiveArtboard(), then either cut/copy the selection with app.copy() or app.cut() and paste it into another document with app.paste(). But I haven't found the option to save the selection in the document.


Solution

  • Basically you can run almost any menu command from a script.

    The script to save the current selection look like this:

    app.executeMenuCommand('Selection Hat 10');
    

    But there will be the dialog window to input a name for this selection.

    enter image description here

    I'm not sure if it's possible to avoid the dialog window and assign the name via a script.