Building RGB values from the layer name?
Hello all,
I've been working on this script and I am stuck. I'm not getting an error, but I don't get the results I'm hoping for.
The objective:
Name the active layer with an RGB value, tell Photoshop to replace the active layer with a new solid fill layer, built with the active layer RGB numbers. Any help is greatly appreciated. ~ Joe D
This is my script at this point:
#target photoshop
//sets global variables for active doc and layer
var doc = app.activeDocument;
var lyr = doc.activeLayer;
var lyrName = lyr.name;
// Check the layer name for eleven chracters or less
if (lyrName.length <= 11) {
var lyrColor = new RGBColor()
lyrColor.RGB = lyrName;
pasteLayernameToRGBField(lyrColor);
} else {
alert("Name the layer with RGB mix (xxx,xxx,xxx)- include commas");
}
function pasteLayernameToRGBField(color) {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc1.putReference( charIDToTypeID( "null" ), ref1 );
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
desc3.putString( charIDToTypeID( "Rd " ), color.red );
desc3.putString( charIDToTypeID( "Grn " ), color.green );
desc3.putString( charIDToTypeID( "Bl " ), color.blue );
desc2.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), desc3 );
desc1.putObject( charIDToTypeID( "T " ), stringIDToTypeID( "solidColorLayer" ), desc2 );
executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );
}
