Creating 3D Models for 3D Printing Using OpenSCAD
by
David Leithauser
Copyright 2020 David Leithauser
All Rights Reserved
Table of Contents
Introduction
Getting Started with OpenSCAD
Basic 3D shapes
3D text
Moving Things Around
Subtracting Parts of Objects
Distorting Objects
Making 3D objects from 2D shapes
Making 3D Models from Pictures
Making 3D Models from Text Files
Duplicating Objects
Math Functions
Making Checking Your Coding Easier
Hinges
Robot
Rotator
Adjustable Cell Phone Stand
Ball Joint
Wheel and Fidget Spinner
Screw Threads
Snap In
Gears
Hollow objects
Lovers
Introduction
Today, 3D printers are becoming more popular and useful. I use them for everything from prototyping my inventions to making custom parts to repair household items to making custom Christmas ornaments. There are many varieties of 3D printers, but one thing they all have in common is that to print something, you have to use a 3D modeling program to create a model. This model is then saved in a special 3D format, most commonly the STL format. Once you have this file, you usually have to run it through a slicer program that converts it to gcode that your printer can understand.
There are many software programs to create the 3D models and save them as STL or other graphic files. Most modeling programs are graphically operated, where you essentially draw the object using your mouse. This has some advantages, but also some drawbacks. Sometimes it can be hard to draw the 3D object on the 2D screen, with the object being stretched or moved in a different direction than you want. It can sometimes be hard to create some shapes, because you are trying to maneuver a 3D object using a 2D display. You may try to move in one direction, but the software interprets your mouse movement on the screen as going in another direction. It can also be hard getting exact dimensions, since you are trying to manually stretch or move objects on your screen with a mouse.
OpenSCAD is a totally free program that takes a different approach. Instead of drawing the object by hand, it lets you describe it by telling it to create a shape like a sphere, cylinder, box, etc. and position it at a certain location. You can then add objects, alter them by doing things like stretching them, cutting away portions, and other operations that give you considerable control of the final product, all by simply writing what you want to do with the objects. This allows for considerable precision. You can view the object you are creating at any time to see how it is going so far.
In this book, I will take you through the process of creating 3D models with OpenSCAD in a step by step manner that I think you will find easy to follow. I will concentrate on the aspects that I find most useful for generating 3D models suitable for 3D printing. I will not get into aspects of OpenSCAD designed to make pictures or 3D movies, such as coloring objects or animation, unless they have some use as a modeling design tool.
I will end the book with a series of chapters called the project section that describe how to make a variety of actual objects that you can use. These give you examples of how to put together the techniques I have discussed in the earlier chapters, and also provide useful components like connectors and moving parts that you can incorporate in your own projects.
I will be using OpenSCAD version 2019.05 for Windows in this book. OpenSCAD is also available for MacOS and Linux. Although I will not be discussing those in this book, most of what I have written should apply to those versions too.
Chapter 1
Getting Started with OpenSCAD
In this chapter, I will tell you how to install OpenSCAD and go over the basic operations like loading and saving files, viewing the objects you are creating, and other fundamentals. I will hold off on how to actually create objects until Chapter 2.
As I mentioned, OpenSCAD is a totally free program. The first step is to download and install it on your computer. Go to the Web site
https://www.openscad.org/downloads.html
You will see a box labeled Windows with four squares inside it. The two on the left download an executable file, while the two on the right download a ZIP file. I recommend downloading the executable file, since installation is much simpler. The ones on the top download the version for 32-bit computers, and the ones on the bottom download the version for 64-bit computers. If you do not know which computer you have, type system in the Windows box that says Type here to search and that will allow you to run the System information program that will tell you. If you still cannot determine I suggest you click on the top left box. The one for 32-bit computers will usually run fine on 64-bit computers, although the 64-bit version will run better. After you click on the appropriate box, the file will be downloaded. Run the executable file to install OpenSCAD.
Once OpenSCAD is installed, run the program. A screen will pop up asking if you want New (create a model from scratch), Open (open a saved model), or Help (open a web page with instructions. There is a box labeled Recents that will list files you recently created and saved, but this will be empty now. There is also a list of directories with sample files. For now, click on New to get an empty setup. The screen will look like this.
On the left side of the screen, you will see a large empty box. This is the text box where you will put the text that describes your model. I will frequently refer to this text as your model code, or simply code throughout this book, and the text area as the code area. On the right you will see a larger box with a coordinate system. In the lower left corner there is also a small marker showing the X, Y, and Z directions. This is viewing area where you will be able to see the model that you create or load. Below this you will see some small icons that help you control the view, which I will explain shortly. Below this is a report box where OpenSCAD reports results of what it is doing, including error messages. At the top you will see a fairly standard menu bar, with options File, Edit, Design, View, and Help.
Just to help demonstrate the viewing, lets load a sample model. Click on the Files menu and a dropdown menu will appear. Move down and click on examples, then click on basics when that appears, and then click on CSG.scad. This will load the CSG sample model (all models have the extensions scad). You should now see a lot of text in the text box. Press the F5 key, and three odd-looking objects should appear in the viewing area.
First, lets rotate and move the view of the model. Place the mouse in the center of the viewing area and then press and hold the left mouse button. Move the mouse right or left to rotate the model. Move the mouse up or down to tilt the model. To move the model instead of rotating it, press and hold the right mouse button while you move the mouse courser around the viewing area. Note that these actions do not actually change the model, only your view of it. For example, if you shifted the view so that the model appeared to be on its side, that does not mean the model would print on its side once you create the STL file. This applies to all the techniques I am describing for shifting your view.