Skip to main content
Disposition_Dev
Legend
December 30, 2016
Answered

Dealing with Compound Paths made of Groups

  • December 30, 2016
  • 4 replies
  • 4095 views

I've had some errors reported by my art team recently and i've traced the issue down to compoundPathItems being composed of groupItems instead of pathItems.

I'm attempting to verify the fill/stroke color of these items which seems to be impossible if the compoundPathItem is made of groups. It seems the only relevant property of compoundPathItem is pathItems (but the length of this property is zero because it only contains groupItems, which is not available).

Does anyone know of a way to access the groupItems nested inside a compoundPathItem???

This topic has been closed for replies.
Correct answer CarlosCanto

Hmm but what if you looked through every groupItem and just saw if its parent is a compound path? Maybe there's less groups in the documents to make it a bit faster.


true, whatever is less but I don't think he has 100k compoundPaths, he could set up a function to "treat" all compoundPathItems, it shouldn't add a big overhead.

app.executeMenuCommand("noCompoundPath"); // release

app.executeMenuCommand("compoundPath"); // make

app.executeMenuCommand("group");

app.executeMenuCommand("ungroup");

4 replies

nickcombs
Inspiring
February 14, 2024

It's been years since I had to deal with this, and I'm surprised there isn't a working function posted here.

 

Anyway, here's what I came up with. Replace the argument in the function call to however you've defined your compound path (or group) item.

var i = {}, doc = activeDocument

firstPathInContainer( doc.selection[0] )



function firstPathInContainer( item ) {

  if( item.pathItems.length ) return item.pathItems[0]

  var path, sel, type

  doc.selection = item

  type = item.typename
  if( type == 'CompoundPathItem' ) 
    app.executeMenuCommand('noCompoundPath')
  else if( type == 'GroupItem' )
    app.executeMenuCommand('ungroup')

  sel = activeDocument.selection
  for( i.sel=0; i.sel<sel.length; i.sel++ ) {
    if( path = firstPathInContainer( sel[i.sel] ) ) break;
  }

  doc.selection = sel
  if( type == 'CompoundPathItem')
    app.executeMenuCommand('compoundPath')
  else if( type == 'GroupItem' )
    app.executeMenuCommand('group')

  return path
}

 

Inspiring
January 7, 2017

Hope you know how to install aip files.

Win only, 64 bit, CC-CC2015. Works with selection. Look at Objects menu.

Here it is.

Seems the plugin works correctly, but I have not tested it much.

Silly-V
Legend
January 7, 2017

Wow cool I'm going to try this out!

So when creating .aip plugins do you always have to create different code for Windows and Mac?

Inspiring
January 7, 2017

The code is basically the same except of GUI (Win32API for Windows). I mean some dialog windows with lots of buttons, input fileds etc. Alerts and warnings can be done with common SDK functions.

But you need Mac to compile plugins for Mac (which I don't have).

CarlosCanto
Community Expert
Community Expert
December 30, 2016

pesky compoundpath groups, you should Release CompoundPath, Ungroup, keep ungrouping until group count reaches zero, re-Make CompountPath...these days it's easy with ExecuteMenuCommand.

Disposition_Dev
Legend
December 30, 2016

I actually had that thought as i was replying to Silly-V's suggestion. However I didn't see any options for releasing compound paths in the executeMenuCommand documentation.. Am i just missing that part??

Here's where i was looking:

Illustrator CC2014 Menu Commands Reference - 手抜きLab@DTPの現場

Silly-V
Legend
December 30, 2016

Ugh there are some ways - here is one: you select the compound path and then go through doc.pathItems and look only at the selected ones - then see each one's .parent property to see if it's a [GroupItem].

#target illustrator

function test(){

  var doc = app.activeDocument;

  var a = doc.compoundPathItems["A"];

  alert("A Path Items: " + a.pathItems.length); // does not reveal true pathItems contents as some are hidden inside a group!

  a.selected = true;

  var thisPath;

  for(var i=0; i<doc.pathItems.length; i++){

    thisPath = doc.pathItems;

    if(thisPath.selected){

      alert(thisPath.parent);

    }

  };

};

test();

I always thought this was a bug, so I tried to use Flatten Transparency whenever possible to eradicate such groups!

Disposition_Dev
Legend
December 30, 2016

thumbs up for a possible solution, but unfortunately it's not one that will work for me..

My artists are running this script on 20-30 files per day and each file routinely has 100k+ pathItems in it. Checking every pathItem in the document is not feasible i'm afraid.

I may actually just abandon support for this script and tell them that they can use it when it works and figure it out themselves when it doesn't. It's merely a single step in the preflight process that can be done relatively easily manually. I think i've already sunk enough time into supporting this minimally important convenience feature.

Silly-V
Legend
December 30, 2016

Hmm but what if you looked through every groupItem and just saw if its parent is a compound path? Maybe there's less groups in the documents to make it a bit faster.