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 14, 2024

I opt for a single compound path per spot fill color because compound paths seem to be the consistent least-problematic type for further boolean operations later in the separation/screen-making process. In screenprinting, screens are typically printed in the order of lightest color to darkest color (darker the inks = more coverage). To make the registration of the screens on-press less tedious, I manually create "traps" for each color screen where the shapes of the current screen are "extended" slightly but only into the areas that will be covered by the screen that follows. Creating these traps just provides a little wiggle room in lining up the screens on the printpress; it compensates for things like slightly warped screens etc. I make these traps by:
-duplicating the current screen's compound path in place
-applying a 1pt stroke of the same color and rounded corners to that duplicated shape
-flattening transparency to convert the stroke to a path ("expand" or "path>outlinestroke" options also work but occasionally fail for reasons I dont fully understand; so i just go for whats more consistent)
-pathfinder unite the duplicate and its new outlined path. and make the result another compound path. 
- merging all colors that will come after the current screen and making that a compound path
- using the merged shape to pathfinder intersect; resulting in a shape that only exists where it will be covered by the screens that follow. 

Similarly, having everything in the design as compound paths is also useful for creating underbase screens where white is being printed beneath the subsequent screens for the sake of brighter colors on dark garments. The white that is printed underneath the other colors has to be choked back and the easiest way ive found to do this is to duplicate everything, pathfinder unite, make compound path, apply a stroke of the same color but at a 0% tint stroke, and send that shape behind the original white shape - the RIP software ignores the stroked area but the choke remains "live" on file and is easily increased/decreased later if need be. 

Keeping everything as compound paths ensures that any individual shapes (like what might be present if the spot color shapes are just left in a group) dont get deleted when pathfinder is used later on making the traps. 

attaching a video of that process because I realize it's a fairly niche workflow and doesnt translate to a text breakdown well. Note: i use a light blue for the white screens just for the sake of visibility against the artboard.


Thanks for the clarification.

 

I will have to think about the task again.