How to find selected Top group layers (layeSets),  relative position

Contributor ,
Feb 27, 2022 Feb 27, 2022

Copy link to clipboard

Copied

Thi is my code to find selected Top group layers (layeSets),  relative position.
I am using it to avoid selecting document active layer using "getByName".

The number can be used at:

app.activeDocument.activeLayer = app.activeDocument.layerSets[2];

I hope it is usefull and correct, since i have almost none exprerience at scripting

( There are similar posts based on ActionManager I think, but I this code is easier to use)

 

 

var sel_name = app.activeDocument.activeLayer.name;
var c = -1;
for(var i = 0; i < app.activeDocument.layerSets.length; i++) {
  if(activeDocument.layerSets[i].typename == "LayerSet")
{c++} 
if (app.activeDocument.layerSets[c].name == sel_name) {
var layerset_index = i;
}
alert(layerset_index);

 

 

 

TOPICS
Actions and scripting

Views

52

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
LEGEND ,
Feb 27, 2022 Feb 27, 2022

Copy link to clipboard

Copied

LATEST
aD = activeDocument, lSs = [].slice
.call(aD.layerSets); while(lSs.length) {
	if (lSs.pop() == aD.activeLayer) {
		alert(lSs.length); break
	}
}

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