Copy link to clipboard
Copied
Hi, I've hit a brick wall now with this, I've scripted making eyelet holes for a banner, at this point, i need to select all objects/ellipses i've made called "Top Eyelet", ready for the next part of the script to distribute them evenly, but I've tried loads of forum examples and other places on google, all I can get anything to do is select one single layer called "Top Eyelet", unfortunately theres at least 6 or 7, i need them all selected.
Most recent attempt was this:
// works, selects only one though
var doc = app.activeDocument;
doc.selection = doc.pageItems.getByName("Top Eyelet");
// still only selects one
var item=app.activeDocument.pageItems
for (var i = 0; i <item.length; i++) {
var doc = app.activeDocument;
doc.selection = doc.pageItems.getByName("Top Eyelet");
}
If anyone can point me in the right direction that would be most appreciated!
Hello, check below sample, it should do what you need
If those objects are always Elipses, then for optimalization you could use pathItems instead of pageItems - there is less items to check, as it's smaller collection.
Typescript version: adobe-forums-scripts/select_pageItems_with_name.ts at select_pageItems_with_name Ā· lumenn/adobe-forums-scripts Ā· GitHub
function selectPageItemsByName(items, name) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (i
...Copy link to clipboard
Copied
Hello, check below sample, it should do what you need
If those objects are always Elipses, then for optimalization you could use pathItems instead of pageItems - there is less items to check, as it's smaller collection.
Typescript version: adobe-forums-scripts/select_pageItems_with_name.ts at select_pageItems_with_name Ā· lumenn/adobe-foru...
function selectPageItemsByName(items, name) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.name === name) {
item.selected = true;
}
}
}
function main() {
var document = app.activeDocument;
var name = 'Top Eyelet';
document.selection = null;
selectPageItemsByName(document.pageItems, name);
}
main();
Copy link to clipboard
Copied
works perfectly, thankyou!
Copy link to clipboard
Copied
Hi,
I tried it with Illustrator 2023, but it ends up with:
Error: 1302: No such element
Line: 7
-> if(item.name ===name){
could you take a look please?
Thanks
Copy link to clipboard
Copied
Change
var item = items;
to
var item = items[i];
The script targets items named "Top Eyelet". You can change that in the fourth line from the bottom.
Copy link to clipboard
Copied
Thank you, it works but the loop filters just the First-level-children.
How can I filter all Elements one by one in the Document?
Copy link to clipboard
Copied
The script iterates the pageItems collection, which includes all items at all levels. So I don't see exactly what the problem is. Can you expound on this?
Copy link to clipboard
Copied
Ops... You are right, the problem is something else.
It wont select the Layers which thier names are between "<" and ">" for example: <name>. Even if I add or remove them in the script as variable "name".
How can I salve this?
Copy link to clipboard
Copied
Items with angle brackets in their label (unless user-created) are unnamed. They correspond to an empty string, i.e. "".
Copy link to clipboard
Copied
So, isn't there a way to salve it?
Whenever you save/export an Illustrator file in PDF-Format, the names of some layers will automaticaly renamed and added angle brackets.
Copy link to clipboard
Copied
If you want to select unnamed items (not layers),
function selectPageItemsByName(items, name) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.name === name) {
item.selected = true;
}
}
}
function main() {
var document = app.activeDocument;
var name = "";
document.selection = null;
selectPageItemsByName(document.pageItems, name);
}
main();
Copy link to clipboard
Copied
Most of the Element's names are in angle brackets, so this won't help me.
Thank a alot for your concern you by the way