How to select sublayer group by name?

New Here ,
Feb 05, 2021

Copy link to clipboard

Copied

Hi community!

How can I select all the items in the sublayer groups called "color" and "shadow"

My main group name in this example called "education-props" is different across all files. Only "color" and "shadow" is consistent and I need the items in these subgroups.

I'm completely new with scripting. Your help is much appreciated!

 

shadow-color.png

 



[ attachment inserted as inline image by moderator ]

TOPICS
Scripting

Views

72

Likes

Translate

Translate

Report

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

1 Correct Answer

New Here , Feb 05, 2021
ellewong New Here , Feb 05, 2021
Oh i think i figured it!var docRef = app.activeDocument;var layers = docRef.layers;docRef.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want.for(var a=0;a<docRef.groupItems.length;a++){if (docRef.groupItems[a].name == "shadow"){docRef.groupItems[a].selected = true;}if (docRef.groupItems[a].name == "color"){docRef.groupItems[a].selected = true;}}

Likes

Translate

Translate
Jump to answer Jump to answer
New Here ,
Feb 05, 2021

Copy link to clipboard

Copied

Oh i think i figured it!

var docRef = app.activeDocument;
var layers = docRef.layers;

docRef.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want.
for(var a=0;a<docRef.groupItems.length;a++){
if (docRef.groupItems[a].name == "shadow"){
docRef.groupItems[a].selected = true;
}
if (docRef.groupItems[a].name == "color"){
docRef.groupItems[a].selected = true;
}
}

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Feb 05, 2021

Copy link to clipboard

Copied

Good finding.

😉

 

Another variant (will be helpful if you have dozens of hundreds of groups)

var aDoc = app.activeDocument;
aDoc.selection = null;
// make sure the layer exists!  or also use a try catch clause
var aLay = aDoc.layers.getByName("education-props");

var grp = null;
try {grp = aLay.groupItems.getByName("shadow");
    grp.selected = true;
    }
catch (e) {alert ("""there is no "shadow" group""")}
try {grp = aLay.groupItems.getByName("color");
    grp.selected = true;
    }
catch (e) {alert ("""there is no "color" group""")}

Likes

Translate

Translate

Report

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