Saturday, April 9, 2016

adobe illustrator - Automatically rotate and translate paths to reduce space without them touching (nesting)


I wrote a script that makes a design for a laser cutter. I want to optimize the layout to reduce waste and make the most of expensive Perspex material. I lay out the pieces so their bounding boxes have 2 mm distance from each other and fit within a 400x600mm sheet. This first picture shows the result of the script, which loses space in the tail of the cursive "j" and in between the "1"'s:


Layout of pieces before optimization and with lost material



This next picture shows some manual optimization: I moved pieces left of the cursive "j" to the right and rotated and squeezed together the "1"'s. Notice how I was able to fit the full "p" and an extra "1" in the same space:


Layout of pieces after optimization and with all material used


I imagine designing such an algorithm would be very involved, but does Inkscape or Illustrator have a way to do this automatically, e.g. "take these SVG's and fit as many as you can into a 400x600mm rectangle"?


Update (July 7, 2018): After the suggestions of @BillyKerr and @Testujin, I tried SVGnest.com. The website had several problems.


First, it ignores stroke width: compare the size of the 1's in the original SVG in the top panel below to their size in the bottom panel. It also changes the original beziergon: compare the "j" in cursive and script, the "a", and the "oe" (French letter) between top and bottom:


SVG file before SVGnest SVG file after SVGnest


Second, the algorithm breaks apart compound paths, such as the outside of the "a" from its hole. The first picture below shows in Illustrator that the "a" is a single compound path, not a group. The second picture shows the result of SVGnest.


Illustrator: the letter SVGnest breaks apart paths


Third, the site runs JavaScript on the client: for a sheet of 400 x 600 mm acrylic with around 40 letters, it was taking 350% CPU with an estimate of over 30 minutes to complete.


A minor point is that the algorithm gets stuck when the material is too large for the objects. The status after 80 iterations was the same as after 1 iteration, with pieces all over:



SVGnest stuck when material is too large




No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...