Skip to main content
jonathankemp
Inspiring
June 8, 2020
Answered

Get layerKind of a specific layer (I got the index) through Action Manager scripting

  • June 8, 2020
  • 4 replies
  • 1675 views

Hey there,

 

I'm looking for a way to get the actual "layerKind" of a layer through Action manager.

 

Now, I know I can get a layerKind with this piece of code, but it's not the actual layerKind like the one you get through "app.activeDocument.activeLayer.kind"

 

function getLayerKindByIndex(theIndex) {
  (r = new ActionReference ()).putProperty(stringIDToTypeID('property'), stringIDToTypeID('layerKind'));
  r.putIndex(charIDToTypeID('Lyr '), theIndex);
  d = executeActionGet (r);

  return d.getInteger(stringIDToTypeID('layerKind'));
}

 

For instance, the function above will return 2 for any Adjustment layer, while "app.activeDocument.activeLayer.kind" will return a much more detailed value like "LayerKind.CURVES" and "LayerKind.HUESATURATION" and so on.

 

Is there any way I can get this detailed layerKind, with AM ?

 

Again... many thanks.

 

J.

This topic has been closed for replies.
Correct answer Manan Joshi

So if the layer is an adjustment you could use the following code

 

 

function getLayerKindByIndex(theIndex) {
  (r = new ActionReference ()).putProperty(stringIDToTypeID('property'), stringIDToTypeID('layerKind'));
  r.putIndex(charIDToTypeID('Lyr '), theIndex);
  d = executeActionGet (r);

	if(d.getInteger(stringIDToTypeID('layerKind')) == 2);
	{
		(r = new ActionReference ()).putProperty(stringIDToTypeID('property'), stringIDToTypeID('adjustment'));
		r.putIndex(charIDToTypeID('Lyr '), theIndex);
		d = executeActionGet (r); 
		var ret = d.getList(stringIDToTypeID('adjustment'))
		if(ret.count)
			return typeIDToStringID(ret.getObjectType(0));
	}
}

 

 

So basically you will have to check layerkind and if its type needs further exploration you would need to move in as i did for adjustment. If the layer kind is 3 then its a textlayer as per the list shared by Kukurykus hence it needs no futher exploration so we stop. For completing the above code you will havw to add new if statements for all the possible values of layerkind can return and handle them accordingly.

 

-Manan

4 replies

jonathankemp
Inspiring
June 9, 2020

Thanks.  This did the trick.

 

Adjustment layers seems to be the only "kind" that need further exploration.

Manan JoshiCommunity ExpertCorrect answer
Community Expert
June 9, 2020

So if the layer is an adjustment you could use the following code

 

 

function getLayerKindByIndex(theIndex) {
  (r = new ActionReference ()).putProperty(stringIDToTypeID('property'), stringIDToTypeID('layerKind'));
  r.putIndex(charIDToTypeID('Lyr '), theIndex);
  d = executeActionGet (r);

	if(d.getInteger(stringIDToTypeID('layerKind')) == 2);
	{
		(r = new ActionReference ()).putProperty(stringIDToTypeID('property'), stringIDToTypeID('adjustment'));
		r.putIndex(charIDToTypeID('Lyr '), theIndex);
		d = executeActionGet (r); 
		var ret = d.getList(stringIDToTypeID('adjustment'))
		if(ret.count)
			return typeIDToStringID(ret.getObjectType(0));
	}
}

 

 

So basically you will have to check layerkind and if its type needs further exploration you would need to move in as i did for adjustment. If the layer kind is 3 then its a textlayer as per the list shared by Kukurykus hence it needs no futher exploration so we stop. For completing the above code you will havw to add new if statements for all the possible values of layerkind can return and handle them accordingly.

 

-Manan

-Manan
Kukurykus
Legend
June 9, 2020
Community Expert
June 9, 2020

Change the return statement to the following and then try

return typeIDToStringID(d.getInteger(stringIDToTypeID('layerKind')));

 

-Manan

-Manan