Copy link to clipboard
Copied
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 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')));
};
Copy link to clipboard
Copied
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')));
};
Copy link to clipboard
Copied
do you have the same code in VBscript ? thanks.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Interesting, I was wondering where the "grain" color came from.. thanks