forked from Paul-Riggott/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getLayersetLayerIDs.jsx
32 lines (31 loc) · 1.66 KB
/
getLayersetLayerIDs.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#target photoshop;
$.writeln("Active Layer Index = " + getActiveLayerIndex());
var lsetInfo = getLayersetLayerIDs(getActiveLayerIndex(),false);
$.writeln("Layer IDs = " + lsetInfo[0]); //Layer IDs in Layerset
if(lsetInfo[1].toString().length >1){
$.writeln("Nested LayerSet Indexs = " + lsetInfo[1]); //Nested layerset indexs
$.writeln("Number of nested layersets = " + lsetInfo[1].toString().split(",").length); //Number of nested layersets
}
function getLayersetLayerIDs(idx,nested){//nested = true = all nested layersets
var layerIDs = new Array();
lSetsIdx = new Array();
for(var y = idx-1, ls=0; ls >= 0 ; y--){
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), y);
var desc = executeActionGet(ref);
var layerSection = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));
if(layerSection==="layerSectionStart"){ ls++; lSetsIdx.push(y);}
else if(layerSection==="layerSectionEnd"){ ls--;} else{
if(nested)layerIDs.push(desc.getInteger(stringIDToTypeID( 'layerID' )));
if(!nested && ls == 0)layerIDs.push(desc.getInteger(stringIDToTypeID( 'layerID' )));
//$.writeln(desc.getString(charIDToTypeID( 'Nm ' )) + " ls = " + ls + " ID = " + desc.getInteger(stringIDToTypeID( 'layerID' )) + " Index = " + y);
}}
return [[layerIDs],[lSetsIdx]];
};
function getActiveLayerIndex() {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
try{ activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){ return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )); }
};