Copy link to clipboard
Copied
Hello guys,
Have a nice day!
Could you please help me create a script?
I have to do this many times and it's really hard.
I appreciate all your help and suggestions.
Thank you so much!
1. I have a selection
2. When I run script will appear a board. I can fill numbers in here. Example with this image:2 Horizontal & 0 vertical
3. Same the above, this is result when I fill: 5 Horizontal & 3 vertical in the board.
// create separations for four point paths;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePathIndex = selectedPath2020 ();
if (thePathIndex != -1) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var thePath = collectPathInfoFromDesc2020 (activeDocument, thePathIndex);
// if path has one subpathitem and four points;
if (thePath.length == 1 && thePath[0].length == 6) {
var originalResolution = activeDocument.resolution
...
It works for me, you must have incorrectly copied/pasted.
Here it is on a platter:
// create separations for four point paths;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePathIndex = selectedPath2020 ();
if (thePathIndex != -1) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var thePath = collectPathInfoFromDesc2020 (activeDocument, thePathIndex);
// if path has one subpathitem and four points;
if (thePath.length
...
Copy link to clipboard
Copied
The Selection would be a bad way to start such a thing as is has no actual corner points (what with being pixels), so you may want to switch to using Paths.
And the vertical lines seem to indicate no perspectival foreshortening – is that your intention?
Copy link to clipboard
Copied
Yes, maybe the selection or the path. Choose the easy way for you.
The shape is a quadrilateral, and when running the script, draws the number of lines in the quadrilateral.
Copy link to clipboard
Copied
That the shape/selection is quadrilateral does not seem to rule out that it may be intended to simulate a perpective, so once again:
Is the apparent absence of perspectival foreshortening intentional?
Copy link to clipboard
Copied
Yes, I just want to divide the quadrilateral into equal parts when I enter the number of vertical and horizontal lines.
Copy link to clipboard
Copied
Easy in Adobe Illustrator with the blend tool if you don't HAVE to do it in Photoshop!
Copy link to clipboard
Copied
Hi bro, Do you can guide detail or link reference? I don't know how to Ilustrator. Thanks!
Copy link to clipboard
Copied
Here is a quick GIF animation, it is hard to tell what is going on as the mouse cursor was not captured:
There should be a ton of tutorial pages and videos on the blend tool if you search, here are two:
https://helpx.adobe.com/au/illustrator/using/blending-objects.htmlhttps://youtu.be/d2rD-36bc48
Copy link to clipboard
Copied
Thank bro, so then can I change to photoshop?
Copy link to clipboard
Copied
// create separations for four point paths;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePathIndex = selectedPath2020 ();
if (thePathIndex != -1) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var thePath = collectPathInfoFromDesc2020 (activeDocument, thePathIndex);
// if path has one subpathitem and four points;
if (thePath.length == 1 && thePath[0].length == 6) {
var originalResolution = activeDocument.resolution;
activeDocument.resizeImage (null, null, 72, ResampleMethod.NONE);
////////////////////////////////////
var sep1 = 3;
var sep2 = 7;
////////////////////////////////////
var point1 = thePath[0][0][0];
var point2 = thePath[0][1][0];
var point3 = thePath[0][2][0];
var point4 = thePath[0][3][0];
var theArray2 = new Array;
theArray2.push(thePath[0]);
////////////////////////////////////
var theDistH1 = (point2[0]-point1[0])/(sep1+1);
var theDistV1 = (point2[1]-point1[1])/(sep1+1);
var theDistH2 = (point4[0]-point3[0])/(sep1+1);
var theDistV2 = (point4[1]-point3[1])/(sep1+1);
for (var m = 1; m <= sep1; m++) {
var point1a = [point1[0]+m*theDistH1, point1[1]+m*theDistV1];
var point2a = [point4[0]-m*theDistH2, point4[1]-m*theDistV2];
theArray2.push([[point1a, point1a, point1a, false], [point2a, point2a, point2a, false], false, 1807])
};
////////////////////////////////////
var theDistH1 = (point3[0]-point2[0])/(sep2+1);
var theDistV1 = (point3[1]-point2[1])/(sep2+1);
var theDistH2 = (point1[0]-point4[0])/(sep2+1);
var theDistV2 = (point1[1]-point4[1])/(sep2+1);
for (var m = 1; m <= sep2; m++) {
var point1a = [point2[0]+m*theDistH1, point2[1]+m*theDistV1];
var point2a = [point1[0]-m*theDistH2, point1[1]-m*theDistV2];
theArray2.push([[point1a, point1a, point1a, false], [point2a, point2a, point2a, false], false, 1807])
};
////////////////////////////////////
var thePath = createPath2018(theArray2, Math.random());
app.preferences.rulerUnits = originalRulerUnits;
strokeLayer (String(sep1+"x"+sep2));
thePath.remove();
// reset;
activeDocument.resizeImage (null, null, originalResolution, ResampleMethod.NONE);
}
};
};
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2020 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
ref.putIndex(cTID("Path"), thePath+1);
/*for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems[l];
if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};*/
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
// case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
}
catch (e) {thisPoint.push(false)};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2018(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// thanks to xbytor;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray[m];
var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath[n];
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO);
// name work path;
var desc30 = new ActionDescriptor();
var ref6 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref6.putClass( idPath );
desc30.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putProperty( idPath, charIDToTypeID( "WrPt" ) );
desc30.putReference( charIDToTypeID( "From" ), ref7 );
desc30.putString( charIDToTypeID( "Nm " ), thePathsName );
executeAction( charIDToTypeID( "Mk " ), desc30, DialogModes.NO );
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var pathDesc = executeActionGet(ref);
var myPathItem = activeDocument.pathItems[pathDesc.getInteger(stringIDToTypeID("itemIndex")) - 1];
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// determine selected path, updated 09.2015 //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
return docDesc.getInteger(stringIDToTypeID("targetPathIndex"));
return app.activeDocument.pathItems[docDesc.getInteger(stringIDToTypeID("targetPathIndex"))]
}
catch (e) {return undefined}
};
////// shape layer //////
function strokeLayer (theName) {
// =======================================================
var idnull = stringIDToTypeID( "null" );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
var idRGBColor = stringIDToTypeID( "RGBColor" );
var idred = stringIDToTypeID( "red" );
var idgrain = stringIDToTypeID( "grain" );
var idblue = stringIDToTypeID( "blue" );
var idcolor = stringIDToTypeID( "color" );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
////////////////////////////////////
var desc11 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putClass( idcontentLayer );
desc11.putReference( idnull, ref4 );
var desc12 = new ActionDescriptor();
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putDouble( idred, 255 );
desc14.putDouble( idgrain, 255 );
desc14.putDouble( idblue, 255 );
desc13.putObject( idcolor, idRGBColor, desc14 );
////////////////////////////////////
var desc15 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc15.putInteger( idstrokeStyleVersion, 2 );
var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
desc15.putBoolean( idstrokeEnabled, true );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc15.putBoolean( idfillEnabled, false );
var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
desc15.putUnitDouble( idstrokeStyleLineWidth, idpixelsUnit, 3.000000 );
var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
var idpointsUnit = stringIDToTypeID( "pointsUnit" );
desc15.putUnitDouble( idstrokeStyleLineDashOffset, idpointsUnit, 0.000000 );
var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
desc15.putDouble( idstrokeStyleMiterLimit, 100.000000 );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleRoundCap = stringIDToTypeID( "strokeStyleRoundCap" );
desc15.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleRoundCap );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
desc15.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleAlignCenter = stringIDToTypeID( "strokeStyleAlignCenter" );
desc15.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter );
var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
desc15.putBoolean( idstrokeStyleScaleLock, false );
var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
desc15.putBoolean( idstrokeStyleStrokeAdjust, false );
var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
var list1 = new ActionList();
desc15.putList( idstrokeStyleLineDashSet, list1 );
var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
var idblendMode = stringIDToTypeID( "blendMode" );
var idnormal = stringIDToTypeID( "normal" );
desc15.putEnumerated( idstrokeStyleBlendMode, idblendMode, idnormal );
var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
var idpercentUnit = stringIDToTypeID( "percentUnit" );
desc15.putUnitDouble( idstrokeStyleOpacity, idpercentUnit, 100.000000 );
var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
var desc16 = new ActionDescriptor();
var desc17 = new ActionDescriptor();
desc17.putDouble( idred, 0.000000 );
desc17.putDouble( idgrain, 0.000000 );
desc17.putDouble( idblue, 0.000000 );
desc16.putObject( idcolor, idRGBColor, desc17 );
desc15.putObject( idstrokeStyleContent, idsolidColorLayer, desc16 );
var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
desc15.putDouble( idstrokeStyleResolution, 72.000000 );
desc12.putObject( idstrokeStyle, idstrokeStyle, desc15 );
////////////////////////////////////
desc12.putString( stringIDToTypeID( "name" ), theName );
desc12.putObject( stringIDToTypeID( "type" ), idsolidColorLayer, desc13 );
desc11.putObject( stringIDToTypeID( "using" ), idcontentLayer, desc12 );
executeAction( stringIDToTypeID( "make" ), desc11, DialogModes.NO );
};
edited
Copy link to clipboard
Copied
What and how exactly should be created to start your script on?
Copy link to clipboard
Copied
Kukurykus, the Script should work on a selected path with four points instead of the originally mentioned selection.
Figuring out the corners of a Selection seems difficult, with a Work Path it’s probably possible but one would have to filter out additional points that might get created …
Copy link to clipboard
Copied
Hi bro, I want like c_pfaffenbichler done above.
Copy link to clipboard
Copied
It really works, but only with 3x7.
How can I enter A x B before it runs?
Copy link to clipboard
Copied
You need to swap out the fixed parameters for variables, with the variables being entered via a prompt:
Change this:
////////////////////////////////////
var sep1 = 3;
var sep2 = 7;
////////////////////////////////////
To something like this:
////////////////////////////////////
// Original input
var sep1input = prompt("Enter the number across:", 3);
// Remove anything that is not a digit or full point
var sep1inputCleaner = sep1input.replace(/[^\d\.]/, '');
// Convert to integer
var sep1toDigit = parseInt(sep1inputCleaner, 10);
// Final result
var sep1 = sep1toDigit;
// Original input
var sep2input = prompt("Enter the number down:", 7);
// Remove anything that is not a digit or full point
var sep2inputCleaner = sep2input.replace(/[^\d\.]/, '');
// Convert to integer
var sep2toDigit = parseInt(sep2inputCleaner, 10);
// Final result
var sep2 = sep2toDigit;
////////////////////////////////////
I have attempted to make the input bulletproof. Anything entered into the prompt field that is not a digit 0-9 or full point character is removed and floats are converted to integers.
Copy link to clipboard
Copied
Thanks, I tried it, but I can't see anything result.
Copy link to clipboard
Copied
It works for me, you must have incorrectly copied/pasted.
Here it is on a platter:
// create separations for four point paths;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePathIndex = selectedPath2020 ();
if (thePathIndex != -1) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var thePath = collectPathInfoFromDesc2020 (activeDocument, thePathIndex);
// if path has one subpathitem and four points;
if (thePath.length == 1 && thePath[0].length == 6) {
////////////////////////////////////
// Original input
var sep1input = prompt("Enter the number across:", 3);
// Remove anything that is not a digit or full point
var sep1inputCleaner = sep1input.replace(/[^\d\.]/, '');
// Convert to integer
var sep1toDigit = parseInt(sep1inputCleaner, 10);
// Final result
var sep1 = sep1toDigit;
// Original input
var sep2input = prompt("Enter the number down:", 7);
// Remove anything that is not a digit or full point
var sep2inputCleaner = sep2input.replace(/[^\d\.]/, '');
// Convert to integer
var sep2toDigit = parseInt(sep2inputCleaner, 10);
// Final result
var sep2 = sep2toDigit;
////////////////////////////////////
var point1 = thePath[0][0][0];
var point2 = thePath[0][1][0];
var point3 = thePath[0][2][0];
var point4 = thePath[0][3][0];
var theArray2 = new Array;
theArray2.push(thePath[0]);
////////////////////////////////////
var theDistH1 = (point2[0]-point1[0])/(sep1+1);
var theDistV1 = (point2[1]-point1[1])/(sep1+1);
var theDistH2 = (point4[0]-point3[0])/(sep1+1);
var theDistV2 = (point4[1]-point3[1])/(sep1+1);
for (var m = 1; m <= sep1; m++) {
var point1a = [point1[0]+m*theDistH1, point1[1]+m*theDistV1];
var point2a = [point4[0]-m*theDistH2, point4[1]-m*theDistV2];
theArray2.push([[point1a, point1a, point1a, false], [point2a, point2a, point2a, false], false, 1807])
};
////////////////////////////////////
var theDistH1 = (point3[0]-point2[0])/(sep2+1);
var theDistV1 = (point3[1]-point2[1])/(sep2+1);
var theDistH2 = (point1[0]-point4[0])/(sep2+1);
var theDistV2 = (point1[1]-point4[1])/(sep2+1);
for (var m = 1; m <= sep2; m++) {
var point1a = [point2[0]+m*theDistH1, point2[1]+m*theDistV1];
var point2a = [point1[0]-m*theDistH2, point1[1]-m*theDistV2];
theArray2.push([[point1a, point1a, point1a, false], [point2a, point2a, point2a, false], false, 1807])
};
////////////////////////////////////
var thePath = createPath2018(theArray2, Math.random());
app.preferences.rulerUnits = originalRulerUnits;
strokeLayer (String(sep1+"x"+sep2));
thePath.remove();
}
};
};
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2020 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
ref.putIndex(cTID("Path"), thePath+1);
/*for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems[l];
if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};*/
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
// case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
}
catch (e) {thisPoint.push(false)};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2018(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// thanks to xbytor;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray[m];
var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath[n];
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO);
// name work path;
var desc30 = new ActionDescriptor();
var ref6 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref6.putClass( idPath );
desc30.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putProperty( idPath, charIDToTypeID( "WrPt" ) );
desc30.putReference( charIDToTypeID( "From" ), ref7 );
desc30.putString( charIDToTypeID( "Nm " ), thePathsName );
executeAction( charIDToTypeID( "Mk " ), desc30, DialogModes.NO );
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var pathDesc = executeActionGet(ref);
var myPathItem = activeDocument.pathItems[pathDesc.getInteger(stringIDToTypeID("itemIndex")) - 1];
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// determine selected path, updated 09.2015 //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
return docDesc.getInteger(stringIDToTypeID("targetPathIndex"));
return app.activeDocument.pathItems[docDesc.getInteger(stringIDToTypeID("targetPathIndex"))]
}
catch (e) {return undefined}
};
////// shape layer //////
function strokeLayer (theName) {
// =======================================================
var idnull = stringIDToTypeID( "null" );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
var idRGBColor = stringIDToTypeID( "RGBColor" );
var idred = stringIDToTypeID( "red" );
var idgrain = stringIDToTypeID( "grain" );
var idblue = stringIDToTypeID( "blue" );
var idcolor = stringIDToTypeID( "color" );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
////////////////////////////////////
var desc11 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putClass( idcontentLayer );
desc11.putReference( idnull, ref4 );
var desc12 = new ActionDescriptor();
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putDouble( idred, 255 );
desc14.putDouble( idgrain, 255 );
desc14.putDouble( idblue, 255 );
desc13.putObject( idcolor, idRGBColor, desc14 );
////////////////////////////////////
var desc15 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc15.putInteger( idstrokeStyleVersion, 2 );
var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
desc15.putBoolean( idstrokeEnabled, true );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc15.putBoolean( idfillEnabled, false );
var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
desc15.putUnitDouble( idstrokeStyleLineWidth, idpixelsUnit, 3.000000 );
var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
var idpointsUnit = stringIDToTypeID( "pointsUnit" );
desc15.putUnitDouble( idstrokeStyleLineDashOffset, idpointsUnit, 0.000000 );
var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
desc15.putDouble( idstrokeStyleMiterLimit, 100.000000 );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleRoundCap = stringIDToTypeID( "strokeStyleRoundCap" );
desc15.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleRoundCap );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
desc15.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleAlignCenter = stringIDToTypeID( "strokeStyleAlignCenter" );
desc15.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter );
var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
desc15.putBoolean( idstrokeStyleScaleLock, false );
var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
desc15.putBoolean( idstrokeStyleStrokeAdjust, false );
var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
var list1 = new ActionList();
desc15.putList( idstrokeStyleLineDashSet, list1 );
var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
var idblendMode = stringIDToTypeID( "blendMode" );
var idnormal = stringIDToTypeID( "normal" );
desc15.putEnumerated( idstrokeStyleBlendMode, idblendMode, idnormal );
var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
var idpercentUnit = stringIDToTypeID( "percentUnit" );
desc15.putUnitDouble( idstrokeStyleOpacity, idpercentUnit, 100.000000 );
var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
var desc16 = new ActionDescriptor();
var desc17 = new ActionDescriptor();
desc17.putDouble( idred, 0.000000 );
desc17.putDouble( idgrain, 0.000000 );
desc17.putDouble( idblue, 0.000000 );
desc16.putObject( idcolor, idRGBColor, desc17 );
desc15.putObject( idstrokeStyleContent, idsolidColorLayer, desc16 );
var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
desc15.putDouble( idstrokeStyleResolution, 72.000000 );
desc12.putObject( idstrokeStyle, idstrokeStyle, desc15 );
////////////////////////////////////
desc12.putString( stringIDToTypeID( "name" ), theName );
desc12.putObject( stringIDToTypeID( "type" ), idsolidColorLayer, desc13 );
desc11.putObject( stringIDToTypeID( "using" ), idcontentLayer, desc12 );
executeAction( stringIDToTypeID( "make" ), desc11, DialogModes.NO );
};
Copy link to clipboard
Copied
Yeah!!! It's work really. Thank you so much! Have a nice day bro.
Copy link to clipboard
Copied
Can you attach a file I could run script on?
Copy link to clipboard
Copied
Any four point path should work.
This jpg contains one:
Copy link to clipboard
Copied
Note, the path must be active/selected before running the script.
EDIT: I don't know how to check for an active path, however one could add a line of code to force the selection to the first path item:
app.activeDocument.pathItems[0].select();
Copy link to clipboard
Copied
sTT = stringIDToTypeID; (ref = new ActionReference())
.putProperty(sTT('property'), sTT('targetPathIndex'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'))
Boolean(executeActionGet(ref).getInteger(sTT('targetPathIndex')) + 1)
Copy link to clipboard
Copied
One more thing, I see that it's good for image with 72ppi. Not work for image 300ppi. Could you please fix it?
Copy link to clipboard
Copied
I'm sure that there must be a more elegant way of dealing with this, however, this brute force approach appears to work in a quick test. Please let me know how it works for you!
// create separations for four point paths;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePathIndex = selectedPath2020();
if (thePathIndex != -1) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var thePath = collectPathInfoFromDesc2020(activeDocument, thePathIndex);
// if path has one subpathitem and four points;
if (thePath.length == 1 && thePath[0].length == 6) {
////////////////////////////////////
// Capture the original resolution ppi value
var origRes = app.activeDocument.resolution;
// Set the resolution to 72 ppi without resampling
app.activeDocument.resizeImage(null, null, 72, ResampleMethod.NONE);
////////////////////////////////////
// Original input
var sep1input = prompt("Enter the number across:", 3);
// Remove anything that is not a digit or full point
var sep1inputCleaner = sep1input.replace(/[^\d\.]/, '');
// Convert to integer
var sep1toDigit = parseInt(sep1inputCleaner, 10);
// Final result
var sep1 = sep1toDigit;
// Original input
var sep2input = prompt("Enter the number down:", 7);
// Remove anything that is not a digit or full point
var sep2inputCleaner = sep2input.replace(/[^\d\.]/, '');
// Convert to integer
var sep2toDigit = parseInt(sep2inputCleaner, 10);
// Final result
var sep2 = sep2toDigit;
////////////////////////////////////
var point1 = thePath[0][0][0];
var point2 = thePath[0][1][0];
var point3 = thePath[0][2][0];
var point4 = thePath[0][3][0];
var theArray2 = new Array;
theArray2.push(thePath[0]);
////////////////////////////////////
var theDistH1 = (point2[0] - point1[0]) / (sep1 + 1);
var theDistV1 = (point2[1] - point1[1]) / (sep1 + 1);
var theDistH2 = (point4[0] - point3[0]) / (sep1 + 1);
var theDistV2 = (point4[1] - point3[1]) / (sep1 + 1);
for (var m = 1; m <= sep1; m++) {
var point1a = [point1[0] + m * theDistH1, point1[1] + m * theDistV1];
var point2a = [point4[0] - m * theDistH2, point4[1] - m * theDistV2];
theArray2.push([
[point1a, point1a, point1a, false],
[point2a, point2a, point2a, false], false, 1807
])
};
////////////////////////////////////
var theDistH1 = (point3[0] - point2[0]) / (sep2 + 1);
var theDistV1 = (point3[1] - point2[1]) / (sep2 + 1);
var theDistH2 = (point1[0] - point4[0]) / (sep2 + 1);
var theDistV2 = (point1[1] - point4[1]) / (sep2 + 1);
for (var m = 1; m <= sep2; m++) {
var point1a = [point2[0] + m * theDistH1, point2[1] + m * theDistV1];
var point2a = [point1[0] - m * theDistH2, point1[1] - m * theDistV2];
theArray2.push([
[point1a, point1a, point1a, false],
[point2a, point2a, point2a, false], false, 1807
])
};
////////////////////////////////////
var thePath = createPath2018(theArray2, Math.random());
app.preferences.rulerUnits = originalRulerUnits;
strokeLayer(String(sep1 + "x" + sep2));
thePath.remove();
////////////////////////////////////
// Reset the original resolution without resampling
app.activeDocument.resizeImage(null, null, origRes, ResampleMethod.NONE);
}
};
};
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2020(myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
ref.putIndex(cTID("Path"), thePath + 1);
/*for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems[l];
if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};*/
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
// case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {
var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))
} catch (e) {
var closed = false
};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
} catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
} catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
} catch (e) {
thisPoint.push(false)
};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID(s) {
return cTID[s] || cTID[s] = app.charIDToTypeID(s);
};
function sTID(s) {
return sTID[s] || sTID[s] = app.stringIDToTypeID(s);
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2018(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// thanks to xbytor;
cTID = function (s) {
return app.charIDToTypeID(s);
};
sTID = function (s) {
return app.stringIDToTypeID(s);
};
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray[m];
var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath[n];
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO);
// name work path;
var desc30 = new ActionDescriptor();
var ref6 = new ActionReference();
var idPath = charIDToTypeID("Path");
ref6.putClass(idPath);
desc30.putReference(charIDToTypeID("null"), ref6);
var ref7 = new ActionReference();
ref7.putProperty(idPath, charIDToTypeID("WrPt"));
desc30.putReference(charIDToTypeID("From"), ref7);
desc30.putString(charIDToTypeID("Nm "), thePathsName);
executeAction(charIDToTypeID("Mk "), desc30, DialogModes.NO);
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated(charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var pathDesc = executeActionGet(ref);
var myPathItem = activeDocument.pathItems[pathDesc.getInteger(stringIDToTypeID("itemIndex")) - 1];
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// determine selected path, updated 09.2015 //////
function selectedPath2020() {
try {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex"));
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var docDesc = executeActionGet(ref);
return docDesc.getInteger(stringIDToTypeID("targetPathIndex"));
return app.activeDocument.pathItems[docDesc.getInteger(stringIDToTypeID("targetPathIndex"))]
} catch (e) {
return undefined
}
};
////// shape layer //////
function strokeLayer(theName) {
// =======================================================
var idnull = stringIDToTypeID("null");
var idcontentLayer = stringIDToTypeID("contentLayer");
var idsolidColorLayer = stringIDToTypeID("solidColorLayer");
var idRGBColor = stringIDToTypeID("RGBColor");
var idred = stringIDToTypeID("red");
var idgrain = stringIDToTypeID("grain");
var idblue = stringIDToTypeID("blue");
var idcolor = stringIDToTypeID("color");
var idstrokeStyle = stringIDToTypeID("strokeStyle");
////////////////////////////////////
var desc11 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putClass(idcontentLayer);
desc11.putReference(idnull, ref4);
var desc12 = new ActionDescriptor();
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putDouble(idred, 255);
desc14.putDouble(idgrain, 255);
desc14.putDouble(idblue, 255);
desc13.putObject(idcolor, idRGBColor, desc14);
////////////////////////////////////
var desc15 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID("strokeStyleVersion");
desc15.putInteger(idstrokeStyleVersion, 2);
var idstrokeEnabled = stringIDToTypeID("strokeEnabled");
desc15.putBoolean(idstrokeEnabled, true);
var idfillEnabled = stringIDToTypeID("fillEnabled");
desc15.putBoolean(idfillEnabled, false);
var idstrokeStyleLineWidth = stringIDToTypeID("strokeStyleLineWidth");
var idpixelsUnit = stringIDToTypeID("pixelsUnit");
desc15.putUnitDouble(idstrokeStyleLineWidth, idpixelsUnit, 3.000000);
var idstrokeStyleLineDashOffset = stringIDToTypeID("strokeStyleLineDashOffset");
var idpointsUnit = stringIDToTypeID("pointsUnit");
desc15.putUnitDouble(idstrokeStyleLineDashOffset, idpointsUnit, 0.000000);
var idstrokeStyleMiterLimit = stringIDToTypeID("strokeStyleMiterLimit");
desc15.putDouble(idstrokeStyleMiterLimit, 100.000000);
var idstrokeStyleLineCapType = stringIDToTypeID("strokeStyleLineCapType");
var idstrokeStyleRoundCap = stringIDToTypeID("strokeStyleRoundCap");
desc15.putEnumerated(idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleRoundCap);
var idstrokeStyleLineJoinType = stringIDToTypeID("strokeStyleLineJoinType");
var idstrokeStyleMiterJoin = stringIDToTypeID("strokeStyleMiterJoin");
desc15.putEnumerated(idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin);
var idstrokeStyleLineAlignment = stringIDToTypeID("strokeStyleLineAlignment");
var idstrokeStyleAlignCenter = stringIDToTypeID("strokeStyleAlignCenter");
desc15.putEnumerated(idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter);
var idstrokeStyleScaleLock = stringIDToTypeID("strokeStyleScaleLock");
desc15.putBoolean(idstrokeStyleScaleLock, false);
var idstrokeStyleStrokeAdjust = stringIDToTypeID("strokeStyleStrokeAdjust");
desc15.putBoolean(idstrokeStyleStrokeAdjust, false);
var idstrokeStyleLineDashSet = stringIDToTypeID("strokeStyleLineDashSet");
var list1 = new ActionList();
desc15.putList(idstrokeStyleLineDashSet, list1);
var idstrokeStyleBlendMode = stringIDToTypeID("strokeStyleBlendMode");
var idblendMode = stringIDToTypeID("blendMode");
var idnormal = stringIDToTypeID("normal");
desc15.putEnumerated(idstrokeStyleBlendMode, idblendMode, idnormal);
var idstrokeStyleOpacity = stringIDToTypeID("strokeStyleOpacity");
var idpercentUnit = stringIDToTypeID("percentUnit");
desc15.putUnitDouble(idstrokeStyleOpacity, idpercentUnit, 100.000000);
var idstrokeStyleContent = stringIDToTypeID("strokeStyleContent");
var desc16 = new ActionDescriptor();
var desc17 = new ActionDescriptor();
desc17.putDouble(idred, 0.000000);
desc17.putDouble(idgrain, 0.000000);
desc17.putDouble(idblue, 0.000000);
desc16.putObject(idcolor, idRGBColor, desc17);
desc15.putObject(idstrokeStyleContent, idsolidColorLayer, desc16);
var idstrokeStyleResolution = stringIDToTypeID("strokeStyleResolution");
desc15.putDouble(idstrokeStyleResolution, 72.000000);
desc12.putObject(idstrokeStyle, idstrokeStyle, desc15);
////////////////////////////////////
desc12.putString(stringIDToTypeID("name"), theName);
desc12.putObject(stringIDToTypeID("type"), idsolidColorLayer, desc13);
desc11.putObject(stringIDToTypeID("using"), idcontentLayer, desc12);
executeAction(stringIDToTypeID("make"), desc11, DialogModes.NO);
};
Copy link to clipboard
Copied
Thank you, it's ok.