Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more