通过脚本在 Adob​​e Illustrator 中创建复合路径

Make compound path in Adobe Illustrator by script

myfile.ai

中有一些复合路径项

如何从 jsx 运行 "Object > Compound Path > Make" 或发送 "ctrl+8"?根据注释 ERROR HERE,我收到错误消息 "A new object cannot be created at the specified location".

#target illustrator

if (app.documents.length > 0) {
    var idoc = app.activeDocument; 
    var cp = idoc.compoundPathItems.add();
    var allPaths = activeDocument.pathItems;
    //Select objects
    for(var i = 0;i < allPaths.length;i++){
        allPaths[i].selected = true;
    }

    var selection = app.activeDocument.selection;
    for (var i=0; i<selection.length; i++) {
        selection[i].move (cp, ElementPlacement.PLACEATEND); // move selected path inside the compound path ERROR HERE 
        selection[i].evenodd = true; // necessary to determine "insideness" or to make holes.  
    }

    alert(selection);
    app.executeMenuCommand("compoundPath");