Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Get layer by index

$
0
0

I am writing the selected layers indexes into an selectedLayers array. Then I am using this:

 

function getLayerNameByIndex(idx) {  var ref = new ActionReference();  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm  " ));  ref.putIndex( charIDToTypeID( "Lyr " ), idx );  return executeActionGet(ref).getString(charIDToTypeID( "Nm  " ));;
}

 

to get the layer name by its index.

Then I am using it like this:

 

var layer = doc.layers.getByName(getLayerNameByIndex(selectedLayers[i]));

 

to get the layer in a variable. NOTE: I don't want to select the layer, I just want to get it into a variable, so I can do this:

 

layer.textItem.contents = "blahblah";

 

Everything of the above works fine currently, but I want to improve it.

So my question would be following: can I get the layer by its ID? Something like doc.layers.getById (instead of doc.layers.getByName)?


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>