• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

Participant ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

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.

TOPICS
Actions and scripting , SDK

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 08, 2020 Jun 08, 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 '), theInd
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Change the return statement to the following and then try

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

 

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

LATEST

Thanks.  This did the trick.

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines