计算 Photoshop 剪切路径点

Counting Photoshop Clipping Path Points

我正在尝试制作一个 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 " );

使用 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.");

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