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

Select multiple objects / pageitems with the same name

Community Beginner ,
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

816

Likes

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;

        if (item.name === n

...

Likes

Translate

Translate
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;

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

Likes

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

Copy link to clipboard

Copied

works perfectly, thankyou!

Likes

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

Likes

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

Copy link to clipboard

Copied

LATEST

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. 

Likes

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