using openscad for 2d machining.

As part of building tweettube, an internet doorbell for Bristol Hackspace, Sam and I decided to blog about some of the things we’ve learnt through the process. I did the case design with openscad, which is a great tool for reusable designs that are easily updated and changed. In particular, I like not having to imagine how a 2d drawing will “fold up” to create a 3d shape. I just play with it on screen until it looks good! Here’s a pic of the model rendered by openscad.

After modelling the case I then exported all the separate pieces as DXFs, and then used a CNC router to cut them out. The files for the case are on github.

It seems more people use openscad for 3d printing than for the 2d processes like laser cutting or CNC routing. I want to show why openscad is a great tool for making designs for these other tools as well.

In the following discussion, I’m going to use a simpler case to make the discussion easier.

If you load this openscad file on your browser (and openscad!) then we’ll go through it section by section:

  • Lines 10 and 11 are specifying things we can’t change: the bolt size and the button size. We design around these bits.
  • Lines 14 to 16 are defining the size of the box. Play with changing the dimensions to see the box change size.
  • Line 19 specifies the thickness of the material we’re working with. Try changing the thickness to see how all the parts change together. Changing material thickness for even a simple design like this in a 2d cad program would be time consuming and repetitive – exactly the type of job computers should be doing for us!
  • Lines 24 to 29 allow you to control what parts of the model are rendered.
  • Lines 31 to 34 are for exporting the DXF. The projection() function of openscad is super cool, and what makes this all possible. The pieces are projected through the z axis and their outlines can be exported to DXF.
  • Lines 39 to 59 define the parts of the model. All the parts are created so they centre on the 0 point of the X,Y and Z axis. This makes it easy to move them about later.
  • Lines 62 to 125 use the previously defined parts, and rotate() and translate() them into position. Take a look at build_front(), below:

module build_front()

First we move the front_or_back() module to the right position to make the front. Then we difference() out the sides, the buttons and the bolts. Because we’ve defined where those things should be in the real world, all the holes get cut out in exactly the right places! I can’t get over how cool this is, but then I’ve been making these kinds of cases with 2d programs for years and it’s so annoying to change them after.

I hope this gives you some inspiration to try openscad for making your files for laser cutting or CNC routing in the future! It’s well worth learning. There’s a good set of tutorials over here from the maker bot guys, and of course the main documentation here. Plus you’ll probably find your local hackspace runs courses on it, or has members who also write about it – thanks Chris Wallace!

To finish, here’s what’s missing from this case in aid of keeping it simple:

  • We’re not rounding all corners for a nice finish. In the tweettube case I rounded the side’s tab corners.
  • We’re not taking into account drill bit radius, so this case would cut fine with a laser, but would need adjustment for milling or routing.
  • We’re using a simplistic way of dealing with using difference() on objects with adjacent faces (the +0.1 on lines 44 and 46). I tend to have one module for the bit I’m going to cut, and an oversized module for the bit I’ll use with difference().

Update! Here are some more links from other people using openscad for 2d work: