-
Notifications
You must be signed in to change notification settings - Fork 68
/
ConvertScript.jsx
79 lines (68 loc) · 2.07 KB
/
ConvertScript.jsx
1
var pathName = "path";var DX = 1000;var PX_NUM = 100;var document = app.activeDocument;var pathItems = document.selection;var itemsLen = pathItems.length;if(itemsLen > 1 || itemsLen < 1) { alert('Please be sure to select one');} else { printPoint();}function printPoint(){ var pathItem = pathItems[0]; var isClosed = pathItem.closed; var pathPoints = pathItem.pathPoints; var pathLen = pathPoints.length; var endPoint; var text = ''; $.writeln('public static Path getHogePath(float width, float[] centerPoint){ \n Path path = new Path();\n'); for(var j = 0; j < pathLen; j++) { var anchorPoint = round(pathPoints[j].anchor); var leftHandlePoint = round(pathPoints[j].leftDirection); var c = (j != 0) ? j - 1 : pathLen - 1; var rightHandlePoint = round(pathPoints[c].rightDirection); if (j == 0) { $.writeln(moveTo(anchorPoint)); text += moveTo(anchorPoint); if (isClosed) { endPoint = cubicTo(anchorPoint, leftHandlePoint, rightHandlePoint); } } else { $.writeln(cubicTo(anchorPoint, leftHandlePoint, rightHandlePoint)); text += cubicTo(anchorPoint, leftHandlePoint, rightHandlePoint); } } if (endPoint) { $.writeln(endPoint); text += endPoint; } $.writeln('return path;\n\n}'); $.writeln('******************************************************************************\n\n\n\n\n\n\n');}function moveTo(anchor){ return pathName + '.moveTo(' + point(anchor) + ');'}function cubicTo(anchor, leftDirection, rightDirection){ return pathName +'.cubicTo(\n ' + point(rightDirection) + ',\n ' + point(leftDirection) + ',\n ' + point(anchor) + '\n);'}//centerPoint[0] - width / 2 + 0.275f * width, centerPoint[1] - width / 2 + 0.008f * widthfunction point(point){ return 'centerPoint[0] - width / 2 + ' + (point[0]) + 'f * width, centerPoint[1] - width / 2 + ' + (-1 * point[1]) + 'f * width'}function round(point){ var p = []; var len = point.length; for(var i=0; i < len; i++) { p.push(Math.round(point[i] / PX_NUM * DX) / DX); } return p;}