Skip to main content
Participant
Feb 5, 2021 10:30 AM UTC
Answered

How to select sublayer group by name?

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!

 

 



[ attachment inserted as inline image by moderator ] 

This topic is closed to new replies. Start a new post to keep the conversation going.
ellewongCorrect answer
Participant
Feb 5, 2021 10:48 AM UTC

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

5 replies

pixxxelschubser
Community Expert
Community Expert
Feb 5, 2021 11:49 AM UTC

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""")}
Translate
Participating Frequently
Apr 29, 2022 1:07 PM UTC

Danke dir, @pixxxelschubser deine Zeilen haben mir auch schon ein wenig weitergeholfen. Da ich leider überhaupt keinen Plan vom scripten habe kommt hier meine Frage: 

Wie wähle ich eine Ebene aus, die noch eine Stufe tiefer sitzt?

In meinem Fall die Ebene "Background". 

 

Danke schon mal im Voraus!

 

Just saw this was an english thread: 

I want to select the sublayer "Background" in the image above. 

Translate
Sergey Osokin
Inspiring
May 2, 2022 5:07 PM UTC

What should the script do if the document contains many layers of the same name?

Translate
ellewongAuthorCorrect answer
Participant
Feb 5, 2021 10:48 AM UTC

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

Translate
Inspiring
Oct 12, 2022 5:26 PM UTC

This worked for me as well, been hours looking for something like this, thanks!

Translate