Hello, OpenSCAD!

OpenSCAD is a modeling program based on a Functional programming language. I use it because I'm a programmer. It's undoubtedly the best way for me to dive into the world of 3D modeling.

I've been using OpenSCAD for years and created some funny things. Some of them include several important ideas and details. To prevent forgetfulness, I decided to write them down. That's why there are OpenSCAD series here.

In fact, OpenSCAD - Documentation has provided a comprehensive explanation of how to use OpenSCAD. It was a good reference while I studied OpenSCAD in the beginning. I didn't go through all of them but grasped necessary information when encountering some problems. Most of the time I spent, actually, were on how to divide and conquer a model and described them in math. So, the documents here will not repeat all the details about syntax and library of OpenSCAD. I would just record some experience and thoughts that are important for me.

Download OpenSCAD

Of course, the first step is to get OpenSCAD. You may download it from the downloads page of the official site. I used the version 2015.03-2 while writing these documents. OpenSCAD uses a date versioning scheme, which uses the year followed by the month of the release.

In the bottom of the same page., there is a Development Snapshots section for downloading the newest builds. Development Snapshots are built irregularly and also use a date versioning scheme. Some new features mentioned on OpenSCAD User Manual might be available in these snapshots; however, stabilities should be under consideration.

Take the Windows version 2015.03-2 for example, both “exe installer” and “zip package” are in a 32-bit and a 64-bit version. You should know what your computer is running, and you may download the zip package directly. After unzipping, move the unzipped folder to where you want. Find and click the “openscad.exe” file in the folder. A Welcome to OpenSCAD dialog will show when opening OpenSCAD for the first time.

Hello, OpenSCAD!

Some Recent files you opened will show on the left side of the dialog for convenient re-opening. There are some built-in Examples shown on the right side. You may study their code if you are interested in how to design these models some day. For now, click the “New” button to create a new file and enter an environment with default settings.

Hello, OpenSCAD!

Use an external Editor

The left side of the above figure shows a default editor of OpenSCAD 2015.03-2. Even though the default editor is better than those in old versions, many people have their preferred editor. You may choose “Hide editor” from the “View” menu to hide the default editor.

Then, use any editor you prefer to edit a text file with the “.scad” filename extension. If you want to input non-ASCII characters, such as traditional Chinese characters, the file encoding should be UTF-8.

Now, in a hello.scad file, try to input some code below.

cube([1, 2, 3]);

The code above will create a cube. Its dimensions x, y and z come from the three value vector [x,y,z]. Then, in the OpenSCAD menu, go to “File”, “Open” and open up hello.scad. You will see a figure such as the following.

Hello, OpenSCAD!

As you can see, my editor is NotePad++ and the picture above demonstrates the way while I am editing and previewing models. You can change the cube's dimensions and save the file again. OpenSCAD can check for changes to files and automatically recompile if a file change occurs. The preview will also reflect the change.

If you don't want OpenSCAD to check for changes to files, you can disable the feature by clicking “Design->Automatic Reload and Preview” in the menu.

Hello, OpenSCAD!

One of the benefits of 3D modeling by programming is you can parameterize your models. That's to say that changing some parameter values in your code will automatically generate a brand-new model.

A “Hello, world!” program is often used to introduce programmers to a new programming language. In that case, let's write a “Hello, OpenSCAD” for example. In your “.scad” file, input the code below.

my_text = "Hello, OpenSCAD!";
step_angle = 30;
step_height = 5;
radius = 30;
height = 5;

len_of_my_text = len(my_text);

for(i = [0:len_of_my_text]) {
    rotate(step_angle * i) 
        translate([radius, 0, i * step_height]) 
                text(my_text[len_of_my_text - i]);

The code above contains some details that need further explanation. They would be the subjects of the latter documents. Once you understand all elements in OpenSCAD and recap this code some day, you'll know how simple it is.

For now, all you have to know about this example is showing the power of 3D modeling by programming. The preview of the above code shows below.

Hello, OpenSCAD!

You may change the values of my_text, step_angle, radius and height. A different model preview will appear. For example, use the values below.

step_angle = 20;
step_height = 5;
radius = 30;
height = 5;

You will see a beautiful stairway formed by the alphabets.

Hello, OpenSCAD!

Pressing left or right mouse button to drag the model so that you can rotate or shift the model respectively.

Render and export as STL

What you see currently is just a preview. That's to say that OpenSCAD didn't calculate all 3D-related data but only draw the visible aspect of the model for you. If you want to export an STL file or other formats, execute “Design->Render” to calculate all 3D-related data. You can also click the F6 key or the hourglass icon in the toolbar, i.e., the second one from the left.

Hello, OpenSCAD!

By the way, you may see axes in the bottom left. They are valuable information for figuring out the positive directions of x-axis, y-axis, and z-axis. You always have to know directions while 3D modeling, doesn't it?

When rendering, the time taken is depending on the complexity of your design and the speed of your computer. If you render the simple example above, it's very fast. Sometimes, it might take a long time. For example, it took me most an hour to render the model below.

Hello, OpenSCAD!

Once you've completed rendering, you may execute “File->Export->Export as STL” to export an STL file or other formats.

Of course, the simple example here is useless for 3D printers because all characters are separated. In the later documents, I'll come up with some funny and printable examples.