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

get layer colour property

Engaged ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

I've wordked out some Action manager code! Go team me! I now have a function that returns the colour of layer - You know you can set them to "red", "violet", "gray" etc.

 

function get_layer_colour_property()
{

  var s2t = stringIDToTypeID;
  var r = new ActionReference();
  var k = "color";
  var p = "layer"
  var r = new ActionReference();
  r.putEnumerated(stringIDToTypeID(p), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
  var d = executeActionGet(r).getEnumerationValue(stringIDToTypeID(k));
  return d;
}

 

So far so good.

However, I get back a string - say for violet it's 1449948192. I say string as it corresponds to teh correct colour, doesn't make any sense as a value.  Not quite what I was expecting, as I thought it might be the four letter code "Vlt ".  

 

So, how do I get the real color layer value (color - DescValueType.ENUMERATEDTYPE)?

 

 

TOPICS
Actions and scripting

Views

1.3K

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 , Dec 07, 2022 Dec 07, 2022

Adobe Photoshop CC JavaScript Reference - a book that should be at hand.

 

If we look at how we can put some value in the ActionDescriptor, we can see that all three arguments must be represented by numeric values

2022-12-08_10-05-53.png

Your code has an example of writing to ActionReference EnumerationValue (yes, it's a different object, but the function is similar):

 

r.putEnumerated(stringIDToTypeID(p), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

 

What's going on here? Each string variable is con

...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

Some code from my scrapbook:

 

// Get the label color
var activeLayerColor = getLayerColour();

function getLayerColour() {
    // Courtesy of Paul Riggott
    // 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')));
}

 

// Set the label color
setLayerLabelCol(activeLayerColor);

function setLayerLabelCol(labelCol) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(c2t("null"), reference);
    descriptor2.putEnumerated(s2t("color"), s2t("color"), s2t(labelCol));
    descriptor.putObject(s2t("to"), s2t("layer"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
}

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
Guide ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

Adobe Photoshop CC JavaScript Reference - a book that should be at hand.

 

If we look at how we can put some value in the ActionDescriptor, we can see that all three arguments must be represented by numeric values

2022-12-08_10-05-53.png

Your code has an example of writing to ActionReference EnumerationValue (yes, it's a different object, but the function is similar):

 

r.putEnumerated(stringIDToTypeID(p), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

 

What's going on here? Each string variable is converted to a numeric type using the stringIDToTypeID function.What do we need to do when reading when we get a numeric type as a result of executing getEnumerationType or getEnumerationType?

2022-12-08_10-09-01.png

 

That's right - execute the function that is the reverse of stringIDToTypeID, that is, typeIDToStringID:

2022-12-08_10-16-54.png

 

function get_layer_colour_property()
{

  var s2t = stringIDToTypeID;
  var r = new ActionReference();
  var k = "color";
  var p = "layer"
  var r = new ActionReference();
  r.putEnumerated(stringIDToTypeID(p), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
  return typeIDToStringID(executeActionGet(r).getEnumerationValue(stringIDToTypeID(k)));
}

 

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
Engaged ,
Dec 11, 2022 Dec 11, 2022

Copy link to clipboard

Copied

LATEST

Thanks jazz-y! I was sooooo close 🙂

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