Draw Shape in Photoshop with JavaScript
Hello,
I have a problem with DrawShape script: Draw Shape in Photoshop with JavaScript · GitHub:
/* Code by Mike Hale http://www.ps-scripts.com/bb/viewtopic.php?f=14&t=1802&start=15
with small modification by Vladimir Carrer
*/
function DrawShape() {
var doc = app.activeDocument;
var y = arguments.length;
var i = 0;
var lineArray = [];
for (i = 0; i < y; i++) {
lineArray = new PathPointInfo;
lineArray.kind = PointKind.CORNERPOINT;
lineArray.anchor = arguments;
lineArray.leftDirection = lineArray.anchor;
lineArray.rightDirection = lineArray.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();
desc91.putDouble(charIDToTypeID("Rd "), 0.000000); // R
desc91.putDouble(charIDToTypeID("Grn "), 0.000000); // G
desc91.putDouble(charIDToTypeID("Bl "), 0.000000); // 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);
myPathItem.remove();
}
// X,Y
// Put the coordinates in clockwise order
DrawShape([100, 100], [100, 200], [200, 200], [200, 100]);
I need to make a modification that will allow to enter Drawshape arguments from a defined array.
By default, the argument must be entered manually into a function as a set of points, for example: [100, 100], [100, 200], [200, 200], [200, 100].
I need to get this effect: DrawShape(myarray), where myarray is defined by function:
var importpoints= "0,26.82;14.44,38.23;10.74,42.89;20.77,50.83;45.78,19.33;21.32,0;0,26.82";
var myarray = importpoints.split(";");
for (var i = 0; i < myarray.length; i++) {
myarray = myarray.split(",");
}
The code that is written does not work. I can not understand how the myarray array should be defined so that it can be used as an argument to the DrawShape function.
Finally, the coordinates I want to load from the txt file, hence the idea to import txt into the table. Sorry for my English.
