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

Select multiple objects / pageitems with the same name

Explorer ,
Jul 31, 2019 Jul 31, 2019

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!

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

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

correct answers 1 Correct answer

Contributor , Jul 31, 2019 Jul 31, 2019

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

...

Votes

Translate

Translate
Adobe
Contributor ,
Jul 31, 2019 Jul 31, 2019

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();

Votes

Translate

Translate

Report

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 ,
Aug 01, 2019 Aug 01, 2019

Copy link to clipboard

Copied

works perfectly, thankyou!

Votes

Translate

Translate

Report

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
Participant ,
Nov 18, 2022 Nov 18, 2022

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

Votes

Translate

Translate

Report

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
Guide ,
Nov 18, 2022 Nov 18, 2022

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. 

Votes

Translate

Translate

Report

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
Participant ,
Dec 01, 2022 Dec 01, 2022

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?

Votes

Translate

Translate

Report

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
Guide ,
Dec 01, 2022 Dec 01, 2022

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? 

Votes

Translate

Translate

Report

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
Participant ,
Dec 01, 2022 Dec 01, 2022

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?Bildschirmfoto 2022-12-02 um 08.13.42.png

Votes

Translate

Translate

Report

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
Guide ,
Dec 02, 2022 Dec 02, 2022

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. "".

Votes

Translate

Translate

Report

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
Participant ,
Dec 02, 2022 Dec 02, 2022

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.

Votes

Translate

Translate

Report

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
Guide ,
Dec 02, 2022 Dec 02, 2022

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();

Votes

Translate

Translate

Report

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
Participant ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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