计算Photoshop剪切路径点

时间:2018-08-07 07:45:03

标签: javascript photoshop extendscript

我正在尝试制作一个Javascript脚本,该脚本可以提醒我文件中有多少剪切路径以及文件中有多少锚点。 (如果剪切路径太复杂,则InDesign将在我们环境中的某些计算机上崩溃)

我在《脚本指南》中找到了对象PathPoint和PathPointInfo,但似乎无法使它正常工作。

我到目前为止所做的是

// pathCount 

// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop

// in case we double clicked the file
app.bringToFront();

var activeDoc = app.activeDocument;


var totalPathItemCount = activeDoc.pathItems.length;

//myPathItem.subPathItems.length;

var myPathItem = activeDoc.pathItems.getByName("CLIPPING");

var mySubPathItem = myPathItem.subPathItems;

var clippingPathPointCount = myPathItem.pathPoints.length;



alert("There are " + totalPathItemCount + " paths and CLIPPING has " + clippingPathPointCount " points " );

2 个答案:

答案 0 :(得分:0)

使用for statement遍历每个subPathItem,并将锚点的计数(即每个subPathItem的计数)添加到clippingPathTotalAnchorCount变量中。例如:

#target photoshop

app.bringToFront();

var activeDoc = app.activeDocument;
var totalPathItemCount = activeDoc.pathItems.length;

// Specifically for the path named "CLIPPING"...
var myPathItem = activeDoc.pathItems.getByName("CLIPPING");
var mySubPathItems = myPathItem.subPathItems;
var mySubPathItemCount = mySubPathItems.length;

// Loop over each subpath of the path named "CLIPPING".
// The count of anchor points for each subpath are added to the total.
var clippingPathTotalAnchorCount = 0;
for (var i = 0; i < mySubPathItemCount; i++) {
  clippingPathTotalAnchorCount += mySubPathItems[i].pathPoints.length;
}

alert("The document has " + totalPathItemCount + " path(s).\r" +
    "The path named CLIPPING has " + mySubPathItemCount + " subpaths,\r" +
    "with a total of " + clippingPathTotalAnchorCount + " anchor points.");

答案 1 :(得分:0)

//Index the item in teh collection with [0]
var mySubPathItem = myPathItem.subPathItems[0];

相关问题