I’m very new at scripting in photoshop and honestly pretty novice at js in general. I apologize if I’m not using the correct terminology.
For very specific and unfortunate reasons, I have to use script to draw a shape layer in the same exact color as the active layer.
I obviously need to get the color of the active layer (by default I think its in RGB but I honestly don’t care if its in hex).
I can’t figure out what line(s) of code will give me the RGB information in a way that I can put into a variable. It is also not in the not-so-handy PDF adobe has for starting scripting in PS.
Thanks!
This is what I have currently for drawing my shape.
in terms of getting selected layer’s color i’ve tried
activeDocument.activeLayer.color but that kicks out as undefined.
function DrawShape() {
var doc = app.activeDocument;
var y = arguments.length;
var i = 0;
var rename = activeDocument.activeLayer.name;
var lineArray = [];
for (i = 0; i < y; i++) {
lineArray[i] = new PathPointInfo;
lineArray[i].kind = PointKind.CORNERPOINT;
lineArray[i].anchor = arguments[i];
lineArray[i].leftDirection = lineArray[i].anchor;
lineArray[i].rightDirection = lineArray[i].anchor;
}
var lineSubPathArray = new SubPathInfo();
lineSubPathArray.closed = true;
lineSubPathArray.operation = ShapeOperation.SHAPEADD;
lineSubPathArray.entireSubPath = lineArray;
var myPathItem = doc.pathItems.add("myPath", [lineSubPathArray]);
var desc88 = new ActionDescriptor();
var ref60 = new ActionReference();
ref60.putClass(stringIDToTypeID("contentLayer"));
desc88.putReference(charIDToTypeID("null"), ref60);
var desc89 = new ActionDescriptor();
var desc90 = new ActionDescriptor();
var desc91 = new ActionDescriptor();
//Here is where I'm thinking I could input the variables for R G B
desc91.putDouble(charIDToTypeID("Rd "), 255); // R
desc91.putDouble(charIDToTypeID("Grn "), 0); // G
desc91.putDouble(charIDToTypeID("Bl "), 204); // B
//
var id481 = charIDToTypeID("RGBC");
desc90.putObject(charIDToTypeID("Clr "), id481, desc91);
desc89.putObject(charIDToTypeID("Type"), stringIDToTypeID("solidColorLayer"), desc90);
desc88.putObject(charIDToTypeID("Usng"), stringIDToTypeID("contentLayer"), desc89);
executeAction(charIDToTypeID("Mk "), desc88, DialogModes.NO);
//Set Opacity, name, and color tag
app.activeDocument.activeLayer.opacity = 50;
app.activeDocument.activeLayer.name = rename;
//Delete path
myPathItem.remove();
};
//grabs current bounds
var LB = activeDocument.activeLayer.bounds;
//draws shape with current bounds. Put the coordinates in clockwise order
DrawShape([LB[0].value, LB[1].value],
[LB[2].value, LB[1].value],
[LB[2].value, LB[3].value],
[LB[0].value, LB[3].value]);
InsiDoubt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.