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

Determine layer color label from layer id?

New Here ,
Nov 18, 2016 Nov 18, 2016

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!

TOPICS
Actions and scripting

Views

4.9K

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

Guide , Nov 18, 2016 Nov 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')));

};

Votes

Translate

Translate
Adobe
Guide ,
Nov 18, 2016 Nov 18, 2016

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')));

};

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
New Here ,
Oct 30, 2019 Oct 30, 2019

Copy link to clipboard

Copied

LATEST

do you have the same code in VBscript ? thanks.

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 ,
Nov 18, 2016 Nov 18, 2016

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

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
Adobe Employee ,
Nov 18, 2016 Nov 18, 2016

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.

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
New Here ,
Nov 23, 2016 Nov 23, 2016

Copy link to clipboard

Copied

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

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