Wednesday, December 2, 2015

AutoLISP Snowflakes



In this article I will describe a technique for making snowflakes similar to those that you may have learned to make as a child, where you fold a piece of paper up into thirds, then fold it in half, then cut out parts.  With this procedure you can obtain a similar result using AutoCAD and then cut it out on a laser engraver.

  1. First of all you need to create a couple of lines at a 30 degree angle to each other.  Select the LINE tool, type 0,0 of the starting point, then rotate up and type 10 on the Y axis or type in 0,10 to create a vertical line 10 units long.
  2. Rotate the line using the ROTATE command, select the line and hit enter, specify the origin as the point of rotation, hit C <enter> to copy and then 30 to rotate 30 degrees.
  3. If you are making a bunch of snowflakes you might want to make this shape into a block.
  4. I like to set up my OSNAP so that I can snap to Nearest.
  5. Use LINE, PLINE or other tools to make the "cuts" in the wedge.  Remember if you are actually cutting on a laser engraver you will want your shape to remain intact.
  6. Delete the two straight lines.
  7. Use the (sf1) macro to make the snowflake. First save the AutoLisp code to snowflake.lsp. Click Manage, Load Application, Select the location with the file snowflake.lsp, type (sf1) at the command line.  You may have to escape a couple of times to exit the command.
  8. If you don't want to use AutoLISP you can just mirror your lines around the 90 degree line, delete the line and then use polar array, repeat 6 to generate the snowflake.

;Snowflake generator
(defun sf1 ()
  (setq p1 (list 0.0 0.0  0.0))
  (setq p2 (list 0.0 10.0 0.0))
  (command "mirror" "ALL" "" p1 p2 "N")
  (command "ARRAYPOLAR" "ALL" "" p1 6 360.0 "" "")
)

Here is another example: