- 首先将所有需要处理的对象按照顺序放入一个数组中:
var selection = [doc.pathItems, doc.compoundPathItems];
var allPathItems = [];
for (var i = 0; i < selection.length; i++) {
for (var j = 0; j < selection[i].length; j++) {
allPathItems.push(selection[i][j]);
}
}
- 利用循环将对象的描边宽度进行调整,同时将复合路径转换为单一路径:
var newWidth = 5; // 新描边宽度
for (var i = 0; i < allPathItems.length; i++) {
var currPathItem = allPathItems[i];
currPathItem.strokeWidth = newWidth;
if (currPathItem.typename == "CompoundPathItem") {
var outlinePath = currPathItem.pathItems[0].pathItems[0].duplicate();
for (var x = 1; x < currPathItem.pathItems.length; x++) {
outlinePath = outlinePath.pathItems.add(currPathItem.pathItems[x].pathItems[0].duplicate());
}
currPathItem = outlinePath;
}
}
- 最终,将处理后的对象重新放入文档中:
for (var i = 0; i < allPathItems.length; i++) {
var currPathItem = allPathItems[i];
var currParent = currPathItem.parent;
currPathItem.move(currParent, ElementPlacement.PLACEATEND);
}
这样,我们就可以批量拓宽描边并将复合路径设置为单一路径了。