Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Make compound path in Adobe Illustrator by script

New Here ,
Sep 08, 2016 Sep 08, 2016

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);

TOPICS
Scripting
2.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 08, 2016 Sep 08, 2016

"Object > Compound Path > Make" as

app.executeMenuCommand("compoundPath");

Translate
Adobe
Community Expert ,
Sep 08, 2016 Sep 08, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2016 Sep 08, 2016

selection.move (cp, ElementPlacement.PLACEATBEGINNING);

The same error in the move line 😃

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2016 Sep 08, 2016

"Object > Compound Path > Make" as

app.executeMenuCommand("compoundPath");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2016 Sep 08, 2016

Thank you! It's working!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2016 Sep 08, 2016

K0r5hun schrieb:

selection.move (cp, ElementPlacement.PLACEATBEGINNING);

The same error in the move line 😃

Only for my interest:

What kind of elements in your document exists?

Please can you show me your layers palette and the error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2016 Sep 09, 2016
LATEST

What kind of elements in your document exists?

There are 4 Compound Paths. I create contur for my image in PSD and export it in *.ai.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines