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)?
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
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
...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);
}
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
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?
That's right - execute the function that is the reverse of stringIDToTypeID, that is, typeIDToStringID:
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)));
}
Copy link to clipboard
Copied
Thanks jazz-y! I was sooooo close 🙂