Skip to main content
Participant
September 8, 2016
Answered

Make compound path in Adobe Illustrator by script

  • September 8, 2016
  • 1 reply
  • 2941 views

There are some compoundPathItems in myfile.ai

How can i run "Object > Compound Path > Make" or send "ctrl+8" from jsx? At line with comment ERROR HERE i get error message "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.selected = true;
  }

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

  alert(selection);

This topic has been closed for replies.
Correct answer Ten A

"Object > Compound Path > Make" as

app.executeMenuCommand("compoundPath");

1 reply

pixxxelschubser
Community Expert
Community Expert
September 8, 2016

K0r5hun​,

does this work for you and can you see the changes?

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.selected = true;

    }

    var selection = app.activeDocument.selection;

    //for (var i=0; i<selection.length; i++) {

    for (var i=selection.length-1; i>0; i--) {

        //selection.move (cp, ElementPlacement.PLACEATEND); // move selected path inside the compound path ERROR HERE

        selection.move (cp, ElementPlacement.PLACEATBEGINNING);

        //selection.evenodd = true; // necessary to determine "insideness" or to make holes.

        cp.pathItems[0].evenodd = true;

    }

}

alert(selection);

Have fun

K0r5hunAuthor
Participant
September 8, 2016

selection.move (cp, ElementPlacement.PLACEATBEGINNING);

The same error in the move line =)

Ten A
Community Expert
Ten ACommunity ExpertCorrect answer
Community Expert
September 8, 2016

"Object > Compound Path > Make" as

app.executeMenuCommand("compoundPath");