Reputation: 6949
In Photoshop, I can change a layer color to violet with
var idsetd = charIDToTypeID( "setd" );
var desc5146 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1552 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1552.putEnumerated( idLyr, idOrdn, idTrgt );
desc5146.putReference( idnull, ref1552 );
var idT = charIDToTypeID( "T " );
var desc5147 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var idClr = charIDToTypeID( "Clr " );
var idVlt = charIDToTypeID( "Vlt " );
desc5147.putEnumerated( idClr, idClr, idVlt );
var idLyr = charIDToTypeID( "Lyr " );
desc5146.putObject( idT, idLyr, desc5147 );
executeAction( idsetd, desc5146, DialogModes.NO );
Is there a way to detect such a layer has been changed from "no color" to red or orange? Get, rather than set? There doesn't seem to be an art layer property for this.
Upvotes: 0
Views: 107
Reputation: 6949
Whilst this doesn't get the colour values directly, the function gets the string associated with the colour which can then be looked up. It can be done with Action Manager code:
// Switch off any dialog boxes
displayDialogs = DialogModes.ERROR; // OFF
var myColour = "violet";
var colCode = get_colour_code(myColour, 2, 0); // get ID back
set_layer_colour(colCode); //set layer colour here
var layerColStr = get_layer_colour_property();
var layerColour = get_colour_code(layerColStr, 1, 2);
alert(layerColour); // violet
// Switch off any dialog boxes
displayDialogs = DialogModes.ALL; // OFF
function set_layer_colour(colstr)
{
var idsetd = charIDToTypeID( "setd" );
var desc5146 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1552 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1552.putEnumerated( idLyr, idOrdn, idTrgt );
desc5146.putReference( idnull, ref1552 );
var idT = charIDToTypeID( "T " );
var desc5147 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var idClr = charIDToTypeID( "Clr " );
var idVlt = charIDToTypeID( colstr );
desc5147.putEnumerated( idClr, idClr, idVlt );
var idLyr = charIDToTypeID( "Lyr " );
desc5146.putObject( idT, idLyr, desc5147 );
executeAction( idsetd, desc5146, DialogModes.NO );
}
function get_colour_code(str, a, b)
{
// num a 0 ID
// num a 1 string
// num a 2 colour
var cols = [
["None", "1315925605", "none"], // None
["Rd ", "1382293536", "red"], // Red
["Orng", "1332899431", "orange"], // Orange
["Ylw ", "1500280608", "yellow"], // Yellow
["Grn ", "1198681632", "green"], // Green
["Bl ", "1114382368", "blue"], // Blue
["Vlt ", "1449948192", "violet"], // Violet
["Gry ", "1198684448", "gray"] // Gray
]
for (var i = 0; i < cols.length; i++)
{
if (str == cols[i][a]) return cols[i][b];
}
return undefined;
}
function get_layer_colour_property()
{
var s2t = stringIDToTypeID;
var k = "color";
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r).getEnumerationValue(stringIDToTypeID(k));
return d;
}
I told ya, you could do it! :)
Upvotes: 1