High-tech modeling for garden railroaders

Part 5: A walk-through of open SCAD software

There are many free modeling programs out there. Each has its advantages and disadvantages.  If you are interested in doing custom models, you should pick one program, learn how it works, and use it exclusively. YouTube is a wonderful resource for tutorials that explain how to effectively use the program. In this article, I’ll quickly cover openSCAD, a free CAD modeling program.

I love to model objects for my railroad. That is because I enjoy the journey as much as I enjoy running the trains. I use a good, free modeling program — openSCAD  (www.openSCAD.org). It uses a descriptive language that allows you to create objects, cut into objects, and otherwise manipulate objects. A “descriptive language” means that you describe the object using a special language. I will walk you through downloading the program and writing a description of a window.

Downloading openSCAD

Open your browser and type in the URL www.openSCAD.org. The picture on the right shows two download links (indicated by arrows) that you can use  to download the program. The file should be “OpenSCAD-2015.03-2-x86-64.exe” — it is about 14Mb in size.  Double click “OpenSCAD-2015.03-2-x86-64.exe” in your browser window or go to the download folder and find it there. This will load the program (photo 1).

If you run another operating system, like Mac OS X, Linux, or UNIX, no worries — they have a program for you. Just pick the right one for you.
Starting openSCAD

Locate the icon on your desktop or in your programs folder. Execute (open) the program by double clicking on the icon.  You will get a welcoming screen such as the picture to the right (photo 2).

A good place to start is with the examples. They will show you some of the basics as well as some of the finer points of the program.
To start, click on “New” and you will get the window to the right (photo 3).

One important thing to remember is that openSCAD does not use millimeters, inches, or anything else. They have their own units that are dimensionless. When the .stl file is created and exported to the 3D printer software, the units will be defined with this software.
What are we going to model?

I am building a factory building, so I need some windows. As usual, I will make a rough-draft drawing with both full-scale and the scaled dimensions (photo 4). According to the notes, the rough opening for this window, in scale, is 3.12” in width and 4.11” in height. The depth of the window is going to be 0.125”.
Putting the model into openSCAD

The very first thing to do is to enter the window’s outside dimension. From there we will add and subtract to form the window.  

So enter into the editor window the syntax: cube(size = [x, y, z]);  For our model, it will come out to cube(size = [3.12, 4.11, 0.125]); Once you do this, you will notice that there is nothing in the graphics window. Not to worry — you have to compile the instructions. Press F5 and the body should appear( photo 5). The red arrow (right) shows the instruction in the editor window (photo 6).

Now we have to cut out the area for the windows. To do this, we will cut out a large area because our mullions are of different thickness than the window frame. We will add the mullions later. We are going to create another cube, then cut this cube out of the cube we just made, subtracting the new cube from the one we have. According to our notes, the area to be cut out is the overall width, subtracting the two outer frames of the window: 3.12 - 0.125 - 0.125 = 2.87. The height would be 4.11 - 0.125 - 0.125 = 3.86. Now we will add another cube: cube(size = [2.87, 3.86, 0.125]);  If we press F5 we see that nothing really happens. That is because we have not told the compiler to subtract one cube from the other. We have actually made two cubes, one inside the other.  To do the subtraction of one cube from another we will use the difference() function.

If you cannot read the editor window, this is what has been written:
difference()  {
  cube(size = [3.12, 4.11, 0.125]);
  cube(size = [2.87, 3.86, 0.126]);

You will see that we have taken one corner out of the cube, which is not exactly what we want. We need a frame that is of equal size around the window. There is an easy fix to this:  I am going to change the cube command to add another option that is available. You can center the cube(s) at the origin. Now everything should be symmetrical around the origin (photo 7).

Here is the way the commands are now written:
difference()  {
  cube(size = [3.12, 4.11, 0.125], center = true);
  cube(size = [2.87, 3.86, 0.126], center = true);

Now we have to add the mullions. To do this, simply add more cubes with the dimensions of the mullions. To make the vertical mullions, we need a cube that is the length of the cube that we subtracted: 3.86. The other dimensions, according to our notes, are 0.1 x 0.1. Let's give it a try (photo 8).

This doesn't look right. I didn't use the “option center = true” because there are three window panes in this direction, so I cannot have one down the middle. There is another command that we can use:  translate([x, y, z]);  That will translate (move) the object to the desired location. In addition, we can use mathematical statements in the translate function (or any of the others like cube) to make things easier.

Let me give a little explanation as to what I did to get the part at the proper location (photo 9).  First here is what the code looks like:

union()  {
  difference()  {
    cube(size = [3.12, 4.11, 0.125], center = true);
    cube(size = [2.87, 3.86, 0.126], center = true);
  translate([2.87/6, 0, -0.0125])
    cube(size = [0.1, 3.86, 0.1], center = true);

You will notice that I have a function union() to start the instructions.  This is because we have to tell the compiler that the part(s) we are adding we want these to be part of our original part.  Using the union() function ties all the cubes that we have generated into one part.

Next I want to translate the mullion (cube(size = [0.1, 3.86, 0.1], center = true);) to the location that I want. The format for the translate command is: translate([x, y, z]).  We know the large area that we cut out to create the “hole” for the windows was 2.87 units and the window itself is centered at the origin. One half of the window equals 2.87/2 units. There are three window panes, so we need to move the mullion 2.87/6 units over. Then, to get it to lay flat on the inside of the window, we need to move it by 0.1 units. We do the same thing for the other mullion, except it needs to go in the negative x direction.

union()  {
  difference()  {
    cube(size = [3.12, 4.11, 0.125], center = true);
    cube(size = [2.87, 3.86, 0.126], center = true);
  translate([2.87/6, 0, -0.0125])
    cube(size = [0.1, 3.86, 0.1], center = true);
  translate([-2.87/6, 0, -0.0125])
    cube(size = [0.1, 3.86, 0.1], center = true);

Now we need the cross mullions (photo 10).  One is in the very center of the window frame.  Therefore I add:
    cube(size = [2.87, 0.1, 0.1], center = true);
But I still have to translate it in the Z direction to make it lay flat against the bottom of the frame. Add another translate:
  translate([0, 0, -0.0125])
    cube(size = [2.87, 0.1, 0.1], center = true);

Now add the other two horizontal mullions and translate those to their proper position  (photo 11):
  translate([0, 3.86/4, -0.0125])
    cube(size = [2.87, 0.1, 0.1], center = true);
  translate([0, -3.86/4, -0.0125])
    cube(size = [2.87, 0.1, 0.1], center = true);
I can now export the window to an .stl file that the printer software can read. Photo 12 shows what was printed.  One thing that I have noticed is that my printer software does not read the openSCAD files correctly. If I measure the frame of the window, they are supposed to be 0.125” x 0.125”.  Instead they measure 0.155” x 0.107”.  The opening that the frame will go into is close: 3.124” (should be 3.12” — close enough) x 4.10” (should be 4.11”). The nice thing about openSCAD is that I don't have to manipulate any graphics — I can just change the code.

That completes the window frame but, since I wanted this for my brick building, I designed a brick facade in SolidWorks (photo 13). (I only chose SolidWorks because it took me about 15 minutes to do it, vs. about two hours for openSCAD. That’s only because I know SolidWorks and am just a beginner in openSCAD.)

Attached is the openSCAD file — you can manipulate it as needed for your project and experiment with the window. Also attached is the .stl file for the window and the façade, so you can print out what I have created here. You can then send it to your local 3D printing facility, go to www.3Dhubs.com and find a printer near you, or drop me an email and I can print it out for you (sberneberg@yahoo.com).

Next time I’ll be working with another free modeler that many have suggested: Sketchup.

Downloadable File(s)


Read and share your comments on this article

Want to leave a comment?

Only registered members of GardenRailways.com are allowed to leave comments. Registration is FREE and only takes a couple minutes.

Login or Register now.


Get the Garden Railways newsletter delivered to your inbox twice a month

By signing up you may also receive occasional reader surveys and special offers from Garden Railways magazine. Please view our privacy policy