Copy link to clipboard
Copied
Hello,
Is there a way to find all active layers with JSX? The 'doc.activeLayer' function seems to target only the first activeLayer in the layer panel
Thanks
1 Correct answer
This is the code to get the information (JavaScript Object) of selected layers in Layer panel. id and index are there, so you may be able to refer to the ExtendScript Layer from it.
/**
* @Version 1.0.0
* @author sttk3.com
*/
/**
* Get the ActionDescriptor of the selected layer of activeDocument
* @Return {Array<any>} [
* {name: string, index: number, id: number, desc: ActionDescriptor}...
* ]
*/
function getSelectedLayerDesc() {
var res = [] ;
var ref1 = new ActionReference(
...
Explore related tutorials & articles
Copy link to clipboard
Copied
This is the code to get the information (JavaScript Object) of selected layers in Layer panel. id and index are there, so you may be able to refer to the ExtendScript Layer from it.
/**
* @Version 1.0.0
* @author sttk3.com
*/
/**
* Get the ActionDescriptor of the selected layer of activeDocument
* @Return {Array<any>} [
* {name: string, index: number, id: number, desc: ActionDescriptor}...
* ]
*/
function getSelectedLayerDesc() {
var res = [] ;
var ref1 = new ActionReference() ;
var idTargetLayers = stringIDToTypeID('targetLayers') ;
ref1.putProperty(stringIDToTypeID('property'), idTargetLayers) ;
ref1.putEnumerated(stringIDToTypeID('document'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum')) ;
var targetLayers = executeActionGet(ref1).getList(idTargetLayers) ;
// if there is a background layer, add 1 to index
var backgroundFactor = 0 ;
try {
activeDocument.backgroundLayer ;
} catch(e) {
backgroundFactor = 1 ;
}
var ref2, tempIndex, desc, layerItem ;
for(var i = 0, len = targetLayers.count ; i < len ; i++) {
ref2 = new ActionReference() ;
tempIndex = targetLayers.getReference(i).getIndex() + backgroundFactor ;
ref2.putIndex(stringIDToTypeID('layer'), tempIndex) ;
desc = executeActionGet(ref2) ;
layerItem = {
name: desc.getString(stringIDToTypeID('name')),
index: tempIndex,
id: desc.getInteger(stringIDToTypeID('layerID')),
desc: desc
} ;
res.push(layerItem) ;
}
return res ;
}
Copy link to clipboard
Copied
This is perfect, thanks for your time!
Copy link to clipboard
Copied
You will also find many examples by searching the forum with the keywords "selected layers”:

