Introduction
When I was in school, many years ago now, I had a few semesters of drafting. Being progressive, we had about a week of computer aided drafting. In those days, that meant punching a few cards that said something like RECT 10 10 5 5 and handing it to a computer operator. Later in the day you came back and picked up a big curly piece of paper that had a rectangle on it. I was less than impressed.
Im primarily an engineer, not a draftsman, and as the state of the art in Computer Aided Drafting (CAD) advanced, it seemed like my prediction was correct: no one wanted to write cryptic commands to drive drawing. They wanted to use a mouse or trackball and draw on the screen as if it were paper.
At about the same time, things were changing in the electronics industry. When I worked for a major semiconductor manufacturer, our computer chip designs were on huge rolls of paper that had been meticulously drawn. As computer design moved from table tops to computer workstations, it seemed obvious that you wanted tools that let you draw those same huge rolls of paper virtually.
Obvious, perhaps, but also wrong. Drawing computer circuits gave way to a much better system that used computer-like languages to describe circuitry. Instead of drawing 96 interconnecting lines, you could write something like ramdata=ram_cs?data[31:0]:32bz;
If you dont know the language, that may seem cryptic but it is compact, succinct, andmost importantif I decide to change the bit width to 16 or 64 or 256 it takes just a second to make that change.
A lot of drafting has gone the same way. There are tools that let you draw as though your computer screen is a piece of paper. Thats not OpenSCAD. OpenSCAD is the great grandson of the old CAD punchcard system I used in school. Of course, there are no cards, it is less cryptic, and it creates 3D objects with relative ease.
Just as computer design moved away from drawing, even the big drawing-style CAD tools often some way to do parametric drafting. OpenSCAD is the extreme. You draw nothing. You describe everything. It shows you a picture of what you described so you can refine your description.
This book will teach you the fundamentals of using OpenSCAD to develop 3D models for printing. You can do a lot of things with OpenSCAD, but Ill only focus on the parts that help you get output from your printer.
I wont talk much about the rules of what makes an object good to print. If you are interested in that, you might want to read one of my other books, Understanding 3D Printing . However, the exact nature of what you can do and cant do varies by the type of printer and material you are using. In general, though, an object needs to have a flat base to sit on the print bed, and there are usually limits to how much material can hang over an edge or cross over a void.
OpenSCAD isnt the best choice for all kinds of 3D modeling. It excels as what I think of as engineering models. Things like front panels, bearings, shimsthings that have regular shapes that you might draw in a drafting class. It is not so good at modeling things that have irregular surfaces like animals or plants or people. You might be able to model some things like that in OpenSCAD, but it would be difficult and frustrating compared to using a program that is made to model artistic objects (like, Blender, for example).
Inside this book, youll find easy-to-digest Chapters that will help you get the most out of 3D drafting with OpenSCAD. If you havent used OpenSCAD, you should probably work through Chapters 1 to 4 in order. The remaining chapters cover more advanced techniques that you could revisit as you need them in any order (more or less).
It is tempting to pad out a book like this with lots of graphics of 3D models. You ll see some in these pages where they help illustrate a point. However, you should really read this book with OpenSCAD open on your desktop. Type in or copy and paste the example code into OpenSCAD and see the output for yourself. Think about a change and try to make it work. Youll learn more that way than just looking at screenshots on the page of the book.
Chapter 1. OpenSCAD and 3D Printing
You can hardly read a newspaper lately without some story appearing about 3D printing. Im going to assume that if you are reading this book, you are familiar with 3D printing (and, if you arent, you might want to check out one of my other books, Understanding 3D Printing, available on Amazon).
The quick summary, though, is that you start with a 3D model (usually in an STL file). The flow in Figure 1.1 shows this in the second row (it assumes you created an STL file in the first row). You run that through a slicing program that cuts the object (conceptually) into thin slices and plots the movement of the printer head for each slice. This outputs a G code file. That file will drive the printer to actually make the object. If you dont own a printer, you might send the model file to a service company to have it printed for you.
Figure 1-1 . 3D Printing Workflow
The point to this book is how do you get that original model file? In other words, how do you go from idea to an STL file (the top row in Figure 1-1). Like most things, there are several possible answers. First, you could download a model from a Web site (like Thingiverse, for example). Thats handy because you dont have to do anything but download it, but it also means you cant get exactly what you want unless you just happen to get lucky.
Another answer is to use a 3D scanner to take a picture (so to speak) of a real world object. Scanners arent very common these days, although there are a few out there. The results are not always that great, either. Plus, sometimes you dont have a real object to start withyou want to create from scratch.
The third way to get an STL file is to create it using a Computer Aided Design (CAD) program or a 3D modeling program. When you think of a CAD program, you usually think of a graphical program that uses the mouse to draw. There are also 3D modeling programs (like Blender) that are more suited for artistic uses. You can certainly use these tools, and many do. However, for complicated drawings it can be painful to use these tools and even more painful to make changes.
Think of an example. You are building an electronic project and you need a front panel with 16 holes for lights and switches. The holes need to line up just right. Most programs will have some kind of alignment tool, of course, but you need to get all the holes in exactly the right spot and lined up by pointing and clicking, using grids, and alignment tools. What if you have to change something? Adding a hole may mean moving a bunch of holes and redoing everything again.
Another form of CAD program is a parametric CAD program (like OpenSCAD). The idea is that instead of drawing a physical shape that describes what you want to build, you actually use a special language to describe the object. This is very similar to a computer program and can have variables and rules. That means I can make changes and things will work out automatically.
Consider that I want to make a cube with a hole exactly 25 millimeters from the edge of the cube and one in the exact center. Instead of drawing it I could describe it with this simple OpenSCAD program:
cubesize =125; // size of cube
offset= 25; // location of one hole
holesize =3; // size of holes
difference() {
cube(cubesize);
// punch hole at offset