Skip to main content
Inspiring
April 12, 2024
Question

help with a script to break apart simple designs

  • April 12, 2024
  • 1 reply
  • 1289 views

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.

This topic has been closed for replies.

1 reply

Kurt Gold
Community Expert
Community Expert
April 12, 2024

Thanks for the detailed description.

However, I think it would be much easier to understand your request if you could provide a sample Illustrator file that shows the initial situation as well as the desired result.

Inspiring
April 12, 2024

That's a good idea. Thank you. Here's one. It's not letting me attach the ai file for some reason. I didnt want to deal with having missing fonts in the file so I converted all the text to outlines for simplicity- just pretend the Initial Design's lettering was live/editable text and the resulting design isn't. haha. This is all for the sake of making screens for screenprinting if that helps clear anything up. It's easier to do the separations when the design is broken up into clean "what you see is all there is" pieces like a puzzle - rather than worrying something is hidden behind something else somewhere that will show up on a screen it doesnt belong. That becomes more of a likelihood with more complicated designs.  I've always been kind of shocked that such a function isn't in Illustrator natively honestly.

Kurt Gold
Community Expert
Community Expert
April 12, 2024

Thanks for the sample file.

One question: Is it really necessary to create separate compound paths for the objects with the same spot fill colour? Or is this just a nice to have thing?