help with a script to break apart simple designs
I've been trying to write a script that essentially breaks up the selection (no opacities/gradients/clippingmasks/etc - just solid vector shapes) and results in a single group of compound paths; one for each spot fill color. I thought it was within my abilities but after numerous do-overs, apparently not.
Ideally, I want it to do the following:
1. go through each item within the current selection (inluding recursively through groups and groups within groups) and:
- if it finds live text, convert it to outlines
- if it finds an item with a stroke, convert that stroke to a path
2. perform pathfinder divide on the selection
note: ive been using the following approach to pathfinder operations which im not sure is the best:
app.executeMenuCommand("group");
app.executeMenuCommand("Live Pathfinder Divide");
app.executeMenuCommand("expandStyle");
app.executeMenuCommand("ungroup");
3. perform pathfinder trim on the selection (I'm not entirely certain this one is necessary - it's just something I've always done when doing it manually)
4. perform pathfinder merge on the selection.
5. go back through the "new" items within the selection (recursively through groups) and delete any "invisible shapes" (no fill color as well as no stroke) that result from the pathfinder functions, and delete them.
6. go back through the items within the selection (recursively through groups) for each item, find all other items within the selection that have the same spot fill color make them all into a single compound path.
7. group the selection
The issue I think I'm running into is not "rechecking/refreshing" the selection to properly update what the script sees to be in it before the script moves on to the the next function. I may be wrong - I'm at a bit of a loss. But it does feel like things stop making sense around the point when it should be uniting/merging shapes of the same fill color before ultimately making them compound paths. I've tried throwing in redraw(); in between steps and that didn't seem to help much. Also, when i got it to somewhat work, it was only "working" on particular item types rather than all. Can anyone help me out?
Thanks in advance.
