Skip to main content
Inspiring
June 30, 2010
Answered

adding multiple paths into a compound path

  • June 30, 2010
  • 2 replies
  • 5699 views

If I use the gui to add multiple paths into a compound path all I have to do is select multiple paths and choose Object->Compound Path->Make (or ctrl-8). When I do this then the bottom path which is filled has holes 'punched through' creating a window in the shape of the smaller paths which were on top of the larger one. For example, a large rectangle with a white fill color is the bottom item and two smaller paths are on top. I create a compound path and whatever is below the new compound path shows through in the largest shape of the previous two smaller paths.

If I use JavaScript and create a new compoundPathItem and move 3 paths into it, with the largest being first, then I get a compound path but only the first of the smaller objects creates a transparent space.

Here is a simplified example:

    var grpMask = doc.groupItems['mask group'];
   
    var compound = grpMask.compoundPathItems.add();
    var pathobj = grpMask.pathItems['bigbox'];
    pathobj.move(compound,ElementPlacement.INSIDE);
    pathobj = grpMask.pathItems['PathLeft'];
    pathobj.move(compound,ElementPlacement.INSIDE);


    pathobj = grpMask.pathItems['PathRight'];
    pathobj.move(compound,ElementPlacement.INSIDE);

In the above example the 'bigbox' path has the left and right paths on top of it but only the left path creates a transparent space in the original box.

I also tried using PLACEATEND instead of INSIDE and grouping the two smaller paths together and moving the group to the compound path.

Merging path items together won't work - I want to keep the original path's closed and intact without drawing a line between them so I can't just add their pathpoints together.

Is move() the best way to add existing paths to a new compound path?

Thanks!

This topic has been closed for replies.
Correct answer chris_gebab

I'm not sure,

have a look at polarity and/or evenodd propertys of pathItems inside the compoundpath.

maybe there is the difference.

?

Chris

2 replies

Inspiring
July 1, 2010

I just set evenodd = true for all of the paths and it worked. Changing the artworkKnockout value manually wasn't necessary.

The docs just say that evenodd If true, the even-odd rule should be used to determine “insideness.” It's a bit vague on the effect of this. The same goes for polarity.

Is there something more complete than the Adobe Illustrator CS4 Scripting Reference: JavaScript guide?

Muppet_Mark-QAl63s
Inspiring
July 1, 2010

if any stumbles across the meaning of the property 'is isolated' then I would like to know because it just don't figure to me…

Inspiring
July 1, 2010

In the UI you can isolate a path or group which greys out all other items on the page and lets you edit just the one that is isolated. If you have lots of overlapping objects and it's hard to alter the ones you want this is probably useful.  That's my take on it anyway. I've only used it in the UI when selecting the right object was difficult.

Muppet_Mark-QAl63s
Inspiring
June 30, 2010

This is odd Im sure I have looked at this before and could not work it out, same result as you. However this time I tried in AppleScript and it worked (to my surprise) so I converted the same commands back to JavaScript and it worked too? I must be going mad…

#target illustrator var docRef = app.activeDocument; with (docRef) {      var x = compoundPathItems.add();      pathItems[0].move(x, ElementPlacement.PLACEATEND);      pathItems[1].move(x, ElementPlacement.PLACEATEND);      pathItems[2].move(x, ElementPlacement.PLACEATEND);      pathItems[3].move(x, ElementPlacement.PLACEATEND); }

Any how a straight forward move of 4 path items 1 large 3 smaller did cut all 3 holes in my test…

chris_gebabCorrect answer
Inspiring
July 1, 2010

I'm not sure,

have a look at polarity and/or evenodd propertys of pathItems inside the compoundpath.

maybe there is the difference.

?

Chris

Muppet_Mark-QAl63s
Inspiring
July 1, 2010

Chris I looked at the 'polarity' the last time I tried this… I can't remember what is different this time around but the 3 hole paths all do turn negative as expected… Edit what may be different is my CS version my Trial CS5 works as I would have expected but CS2 does not but changing the polarity does get around this… This worked in CS2

#target illustrator var docRef = app.activeDocument; with (docRef) {      var x = compoundPathItems.add();      for (var i = 0; i <= 3; i++) {           pathItems.move(x, ElementPlacement.PLACEATEND);           if (i < 3) {                x.pathItems.polarity = PolarityValues.NEGATIVE;           }      } }