CAD for Hobbyists: OpenSCAD

Completed Bottle Opener
Completed Bottle Opener

OpenSCAD is not what most would consider a conventional CAD package.  In most CAD programs to create a shape you have to in some form draw or sculpt the desired shape; this is not the case in OpenSCAD.  In OpenSCAD shapes are defined by functions and you don’t draw shapes but program them.  Each 3D model is defined by a script that is then compiled into a 3D shape.  It is after all called The Programmers Solid 3D CAD Modeler.

Now, the fact that parts are programmed and not drawn is a large departure from other CAD programs and as such takes some getting used to.  In other CAD packages if you wanted to place a hole in a plate you would simple sketch the hole roughly where it should go and then define its exact size and position later.  In OpenSCAD you cannot do this; you need to have a rough idea of where a component needs to be placed and how it should be size.  When creating shapes in OpenSCAD you start by creating a primitive shape (cylinder, cube/box, etc.) and combine them using boolean operations (union, intersect, difference).

Using these primitive shapes, translating/scaling, and then combining them can be tedious to create a 3D model, however, because the 3D model is defined by a script, it is very easy to modify.  To change the size or position of a hole for example, you simply modify the dimensions in the script and recompile the part.   Due to these easy customization of a 3D model, OpenSCAD has become very popular in the 3D printing community.  A gallery of parts that have been created with OpenSCAD (and often 3D printed) can be found here.

Sample Project

When you first launch OpenSCAD you are presented with an empty project.  The screen displays your script on the left half and the compiled part/3D window and console on the right half of the screen.  I had not used OpenSCAD much before and found the built in example files along with the online cheat sheet very helpful.  To start building the bottle opener in OpenSCAD we first define a rectangular solid using the cube command.

Creating the Bottle Opener Body
Creating the Bottle Opener Body

When we first create the part we see that we are zoomed very far out.  In OpenSCAD there aren’t any real world dimensions.  All of the distance/size dimensions are unitless and any 3D models that are produced need to be properly scaled when they are exported.

Zooming In to show Size
Zooming In to show Size

The next thing we want to do is cut out the keyring hole in the bottle opener.  To do this I first create the cylinder that I am going to use to subtract from the main object.  When creating parts in OpenSCAD they by default are created centered around the origin.  If you want to have the part created in a different location you use the translate command.

The cylinder for the keyring is created by translating to the location at which it will be located and by then creating a cylinder of the proper size.  The length of the cylinder is made thicker than the bottle opener to make sure it fully cuts through both sides of the bottle opener.

Cylinder for Keyring Hole
Cylinder for Keyring Hole

When we initially create the cylinder for the keyring we see that it is displaying as a pentagonal prism and not a nice circular shape.  This is due to the number of facets being used to represent our 3D shape.  This is a setting that can be updated to increase the visual fidelity of our rendering.

Increasing resolution of rendering
Increasing resolution of rendering

With the cylinder for the keyring hole the proper size and in the correct position we use the difference command to cut it out of the bottle opener.  The difference command uses the first shape defined within it as the body to cut from and the second shape defined in it as the part to cut out.

Cutting the Keyring Hole
Cutting the Keyring Hole

With the keyring cut, we next want to cut out the bottle opener opening.  I use a combination of rotate, translate and the cube commands to create the shape of the bottle opener opening.  The difference command is again used to perform the cutting operation.

Building bottle opener opening
Building bottle opener opening
Overlaying the Bottle opener opening
Overlaying the Bottle opener opening
Cutting out the opening
Cutting out the opening

With both the keyring hole and bottle opener opening cut out the only thing left to do is to chamfer the keyring hole.  Unlike in traditional CAD programs where a chamfer command could be used, in OpenSCAD you have to create a cone and cut it away from the part.

The cylinder command was used to create a cone that provided the proper chamfer and difference was again used to cut the chamfer.  This series of operations was performed twice, once for each end of the keyring hole.

Building cone for keyhole chamfer
Building cone for keyhole chamfer
Top chamfer cut out
Top chamfer cut out
Building cone for bottom Chamfer
Building cone for bottom Chamfer

Conclusion

OpenSCAD is a very powerful 3D modeling program and its widespread use in the 3D printing community makes it an obvious choice for many hobbyists.  However I find having to program your part and not being able to draw a component un-intuitive.  I found that to create a part in OpenSCAD you pretty much had to have it already designed on paper.  For someone who prefers to sketch concepts before the put them in a CAD program (this includes me) this isn’t a hurdle, but for some it may be.  Additionally, while it is possible to create multi-body parts that function like an assembly in other CAD programs, OpenSCAD does not support assemblies or the importing of 3D party components.

Leave a Reply

Your email address will not be published. Required fields are marked *