Skip to main content
Simon Henke
Known Participant
June 19, 2019
Answered

Action Manager: get Layer by Index

  • June 19, 2019
  • 1 reply
  • 1862 views

Hi,

does anyone know how to get the layer (object reference) by it's index (action manager index)?

I've googled for quite a long time but all I can find is something like

function getLayerNameByIndex( idx ) {  

    var ref = new ActionReference();  

    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm  " ));  

    ref.putIndex( charIDToTypeID( "Lyr " ), idx ); 

    return executeActionGet(ref).getString(charIDToTypeID( "Nm  " ));;  

}; 

however I don't need the name or id of the layer, I need the layer object itself..

My tries of altering the above code weren't successfull unfortunately.

This topic has been closed for replies.
Correct answer r-bin

1. Cycle through all layers and LayerSets. Compare the itemIndex property of the layer (folder) with the required index. If it matches, use this layer. (CC2015+)

2. Select a layer using the index and AM code for selecting layer by index. ActiveLayer - the desired layer.

No more options.

1 reply

r-binCorrect answer
Legend
June 19, 2019

1. Cycle through all layers and LayerSets. Compare the itemIndex property of the layer (folder) with the required index. If it matches, use this layer. (CC2015+)

2. Select a layer using the index and AM code for selecting layer by index. ActiveLayer - the desired layer.

No more options.

Simon Henke
Known Participant
June 19, 2019

Thanks for your reply!

I've thought of those two options as well, currently using the second one. Unfortunately it will change the active layer and one would have to restore the orginally selected layers (which can be hard for multiple ones).

At least I know now that there's no other option