So you have a 3D printer, and you’re getting tired of printing out octopodes and weighted companion cubes. Good! With a 3D printer, you can make just about anything, but only if you have the modeling experience to turn your design into an .STL file. This 3D Printering column is going on a tangent for a few weeks with some tutorials on how to make a ‘thing’.
This week, we’re starting off with OpenSCAD, a 3D modelling program that’s more like programming than drawing. A lot of useful 3D printable objects – including the parts for a lot of RepRaps – are designed in OpenSCAD, so hopefully by the end of this you’ll be able to design your own parts.
This isn’t meant to be a complete tutorial for OpenSCAD; I’m just demoing SCAD enough to build a simple part. Next week I’ll most likely be designing a part with AutoCAD, but if you have an idea of what software tools I should use as a tutorial to make a part, leave a note in the comments. Check out the 3D Printering guide to making a part with OpenSCAD below.
First, some basics

The basic idea behind OpenSCAD is constructive solid geometry this is a modeling technique that uses basic primitives such as a sphere, cube, or cylinder along with basic boolean operations to create an object. Using words to describe this technique is just terrible, so here’s a very, very short example. To the right is a pic of two objects created in OpenSCAD, a cube and a cylinder Below is the code, which you should be able to follow easily:
module example() { sphere(10); translate([15,15,-10]){ cylinder(h=20, r=5); }}example();
Brain dead simple, right? We’re just creating a sphere with a radius of 10 and a cylinder with a radius of 5 and a height of 20. We’re translating the cylinder in space by 15 units in the x and y axes, and down 10 units in the z axis. Here’s where constructive solid geometry comes in. We can combine those two 3D primitives by using the union() command like so:
union(){ sphere(10); translate([0,0,-10]){ cylinder(h=20, r=5); } }
In OpenSCAD, the union command is implicit. Most of the time, you don’t need it, except in cases where you’re combining other boolean operations. There are two more boolean operations we can use – difference, or just subtracting one object from another, and intersection. Here is the difference command:
difference(){ sphere(10); translate([0,0,-10]){ cylinder(h=20, r=5); } }
And the intersection command:
intersection(){ sphere(10); translate([0,0,-10]){ cylinder(h=20, r=5); } }
That’s constructive solid geometry. With these boolean operations, you can make just about anything. I suppose it’s time to demonstrate that, huh?
Our Thing

Since I’m going to be doing several tutorials of how to build a ‘thing’, it makes sense to have one standard ‘thing’ to make with these tutorials. Choosing an object to copy was unexpectedly hard, but after pulling out a few books on engineering drawing and drafting, I settled on the above ‘thing’, from Engineering Drawing (French, 1929). If you’re wondering why I chose something so odd out of a book so old, just remember: the guys who designed the Apollo spacecraft learned drafting and drawing with this book. Also, this is my column, so deal with it. By combining a few cylinders and cubes it’s fairly easy to create a very basic shape of what will become our finished part. The initial code is below, along with a render:
module thing(){ difference(){ cylinder(h=7, r=19); cylinder(h=7, r=8); } translate([-23,10,0]){ cube([46, 10, 7]); } translate([-10,-26,0]){ cube([20, 16, 7]); } translate([-10,-26,7]){ cube([20,4,7]); }}thing();
Again, this is just the beginning of our part. we’re only using cubes and cylinders here. If you’re wondering why the dimensions we’re using are so odd, it’s because the original part (published in my fourth edition copy of Engineering Drawing in 1929, but it could be from the first edition published in 1911) was designed in eighths of an inch. I’m just writing my OpenSCAD so one unit is equal to one eighth of an inch. When we print this out, we can fix any size issues just by multiplying. To finish up the main body of our part, we need to add a few cylinders on the flange. One thing that’s really cool about OpenSCAD is the ability to create small parts and later combine them with the union command. Here’s a collection of cylinders for our flange:

module flange() { rotate([270,0,180]){ translate([-10,6,-4]){ difference(){ union(){ cube([20,12,4]); translate([10,0,0]){ cylinder(h=4, r=10); } } translate([10,0,0]){ cylinder(h=4,r=3.5); rotate([0,0,90]){ cylinder(h=3, r=7); } } } } }}Because OpenSCAD is basically just code, we can simply call this module at the relevant space in the code. You can see this in the finalized code a few scrolls down. Right now our part looks like this: Now the only thing left to add to this thing is the 3/8″ slot on the main body, and a few fillets. I’ll leave the fillets as an exercise to the reader, but here’s the code and a pic for the resulting part:

module thing(){ difference(){ cylinder(h=7, r=19); cylinder(h=7, r=8); rotate([0,0,225]){ translate([0,1.5,0]){ cube([20,3,7]); } } } translate([-23,10,0]){ cube([46, 10, 7]); } translate([-10,-26,0]){ cube([20, 10, 7]); } translate([0,-26,24]){ flange(); }}module flange() { rotate([270,0,180]){ translate([-10,6,-4]){ difference(){ union(){ cube([20,12,4]); translate([10,0,0]){ cylinder(h=4, r=10); } } translate([10,0,0]){ cylinder(h=4,r=3.5); rotate([0,0,90]){ cylinder(h=3, r=7); } } } } }}thing();

So there you go. A thing, created with OpenSCAD. Is this the definitive guide to designing stuff with OpenSCAD? No, but it’s more than enough to get your feet wet. It’s enough so you can design your own parts and send them over to a 3D printer. Next week, I’ll be making the same part in AutoCAD, which should translate well to other CAD packages. If you have any desire to see this part made with another 3D design package, leave a note in the comments.

Filed under: 3d Printer hacks, Hackaday Columns