Skip to main content
Participating Frequently
November 18, 2016
Answered

Determine layer color label from layer id?

  • November 18, 2016
  • 3 replies
  • 5696 views

Hi,

 

Does anyone know if it's possible to determine the layer color label that's shown to the left of the layer name? I tried to determine the color label using the following method, however this isn't returning the expected result. I'm using photoshop CC 2015.

 

var ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), layer.id);
var desc = executeActionGet(ref);
var color = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID("color")));

 

The color variable is consistently returning "grain". Please let me know if anyone knows how to get the color from the layer label.

 

Thanks in advance!

This topic has been closed for replies.
Correct answer SuperMerlin

This is using the layer ID.

$.writeln(getLayerColourByID(4));

function getLayerColourByID( ID ) {

var ref = new ActionReference();

ref.putProperty( charIDToTypeID("Prpr") ,stringIDToTypeID('color'));

ref.putIdentifier(charIDToTypeID( "Lyr " ), ID );

return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('color')));

};

3 replies

Tom Ruark
Inspiring
November 18, 2016

stringIDToTypeID('grain') == stringIDToTypeID('green')

Long long ago in a galaxy far far away we made a mistake and did this:

#define keyGrain 'Grn ' // CONFLICT: keyGreen.

and this

#define keyGreen 'Grn ' // There is also an enumGreen. CONFLICT: keyGrain.

And Photoshop invented a new color.

I tried to fix once but there was too much "legacy" code and everyone voted to leave it alone...sorry.

And add a ref.puProperty(... for that key) so you don't waste time getting ALL of the keys on the layer.

Participating Frequently
November 23, 2016

Interesting, I was wondering where the "grain" color came from.. thanks

pixxxelschubser
Community Expert
Community Expert
November 18, 2016

Hi juliel96058674​,

you can set the active layer label color:

// layer_setLayerColor_layerLabel.jsx

// "none","red","orange","yellowColor","grain","blue","violet","gray"

// set the color you want

// regards pixxxel schubser

function layerLabel () {

    var target = new ActionDescriptor();

        var ref1 = new ActionReference();

        ref1.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    target.putReference( charIDToTypeID('null'), ref1 );

        var colorize = new ActionDescriptor();

        colorize.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID('None') );

        //colorize.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID("red") );

    target.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), colorize );

    executeAction( charIDToTypeID('setd'), target, DialogModes.NO );

};

layerLabel ();

you can get the active layer label color (IMHO years ago written by Paul Riggott )

alert(getLayerColour());

function getLayerColour(){

//Colours returned ....

// "none","red","orange","yellowColor","grain","blue","violet","gray"

var ref = new ActionReference();

   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

   var appDesc = executeActionGet(ref);

  return typeIDToStringID(appDesc.getEnumerationValue(stringIDToTypeID('color')) );

};

Have fun

SuperMerlin
SuperMerlinCorrect answer
Inspiring
November 18, 2016

This is using the layer ID.

$.writeln(getLayerColourByID(4));

function getLayerColourByID( ID ) {

var ref = new ActionReference();

ref.putProperty( charIDToTypeID("Prpr") ,stringIDToTypeID('color'));

ref.putIdentifier(charIDToTypeID( "Lyr " ), ID );

return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('color')));

};

Participant
October 30, 2019

do you have the same code in VBscript ? thanks.