Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Select objects with the same name in illustrator

Explorer ,
Oct 05, 2016 Oct 05, 2016

I ave several objects on the page all with the same id "bars" How do I select all of them at one time. i've been trying something like this

app.activeDocument.pages[0].allPageItems[1].constructor.name == "bars";

but getting no result. Sorry very rusty on extend script and just getting back into it. Any help appreciated

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
People's Champ ,
Oct 05, 2016 Oct 05, 2016

Hi,

app.activeDocument.pages[0].allPageItems[1]

seems like InDesign script. Illustrator has no concept of pages and the property allPageItems neither exist in the Illustrator DOM.

app.activeDocument.pageItems will however return every single item just as allPageItems for InDesign. So you can loop through them and check the type for action.

Keep in mind though that it may be more efficient and precise to reference the specific illustrator collection of items such as pathItems, groupItems, etc. )

HTH

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2016 Oct 05, 2016

Thanks for that, I did this:

  var item=app.activeDocument.pageItems

    for (var i = 0; i <item.length; i++) {

        if(item.name=="bars") {

            item.selected=true;

            }

        }

which seems to work. I was just hoping there woas a more direct way to access object with the same name then highlight them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 05, 2016 Oct 05, 2016

The usual tricks I can think of with iNDesign doesn't seem to be used with Illustrator so I guess it's the only way to do.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2016 Oct 05, 2016

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2016 Oct 05, 2016

if "bars" Objects were in their own layer you could select them all with Layer.hasSelectedArtwork

also, if "bars" Objects had a Note "bars", you could run an action to select all objects whose Notes match "bars"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 15, 2016 Oct 15, 2016

var name = "bars"; var objectsWithNameBars = new Array(); for(var i=0; i< app.documents[0].pageItems.length;i++){     var item = app.documents[0].pageItems;     if(item.name.toLowerCase() == "bars")           objectsWithNameBars.push(item) } app.selection = objectsWithNameBars; This code will select all objects with name BARS, bars or BARS. Hope its helpful

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 16, 2016 Oct 16, 2016
LATEST

Yes but it's still about looping through objects. InDesign has a concept of collections and methods that allow reaching members of the collection.

So basically it would be something like myPageItems.everyItem().doSomething() or myPageItems.everyItem().aProperty = …

Nothing similar with Illustrator as it seems to be.

FWIW

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines