Copy link to clipboard
Copied
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);
"Object > Compound Path > Make" as
app.executeMenuCommand("compoundPath");
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
selection.move (cp, ElementPlacement.PLACEATBEGINNING);
The same error in the move line 😃
Copy link to clipboard
Copied
"Object > Compound Path > Make" as
app.executeMenuCommand("compoundPath");
Copy link to clipboard
Copied
Thank you! It's working!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now