How to select sublayer group by name?

New Here ,
Feb 05, 2021 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

213

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

New Here , Feb 05, 2021 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
New Here ,
Feb 05, 2021 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 05, 2021 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

Copy link to clipboard

Copied

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?

Bildschirmfoto 2022-04-29 um 15.03.38.png

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. 

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
Explorer ,
May 02, 2022 May 02, 2022

Copy link to clipboard

Copied

LATEST

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

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