Skip to main content
Inspiring
November 27, 2011
Answered

Selecting Symbols on page by name

  • November 27, 2011
  • 1 reply
  • 3641 views

Im struggling with the correct use of symbol / symbol items in applescript. I can successfully list the symbols used on the page, but I cannot select them. Any suggestions on how I can select all the items on the page that are Symbol Items of symbols named "Apples" but not oranges? After that I hope to replace the instances matching the height or width of the items whichever is greater with a 3rd item name. Any suggestions would be great. Javascript is always an option as well but I had the same difficulty.

This topic has been closed for replies.
Correct answer CarlosCanto

here's how to do it with JS

var idoc = app.activeDocument; // get active document

for (i=0; i<idoc.symbolItems.length; i++) // loop thru all symbol items in the active document

          {

                    var symbolitem = idoc.symbolItems; // get each symbol item

                    if (symbolitem.symbol.name == "Apples") // check if it is an instance of "Apples" symbol

                              {

                                        symbolitem.selected = true; // if it is, then select it

                              }

          }

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
November 27, 2011

here's how to do it with JS

var idoc = app.activeDocument; // get active document

for (i=0; i<idoc.symbolItems.length; i++) // loop thru all symbol items in the active document

          {

                    var symbolitem = idoc.symbolItems; // get each symbol item

                    if (symbolitem.symbol.name == "Apples") // check if it is an instance of "Apples" symbol

                              {

                                        symbolitem.selected = true; // if it is, then select it

                              }

          }

schroef
Inspiring
April 20, 2023

Ive got a versio with a prompt asking for a name, then user wont need to edit it each time

 

// SelectSymbolsByName
// https://community.adobe.com/t5/illustrator-discussions/selecting-symbols-on-page-by-name/m-p/3745080#M229883

var docRef=app.activeDocument;
var symbolName=prompt("Enter the name of the Symbol you want to be selected object","Enter Name");
if(symbolName){
    for(i=0;i<docRef.symbolItems.length;i++){
        try{
            sym = docRef.symbols.getByName(symbolName)
        } catch (e) {
            // alert(e)
            alert("Symbol "+symbolName+" can not be found")
            break
        }
        var currInstance=docRef.symbolItems[i]
        if (currInstance.symbol.name == symbolName){
            currInstance.selected=true;

        }
    }
}
redraw();