In this series of OpenSCAD tutorials we’ve covered the basics of the OpenSCAD interface, how to make 2D forms, how to make some basic 3D forms, how to position those forms in 3D space, and the different ways to combine forms. Although I described the last tutorial as an “intermediate” level, that’s really only because you learned the basics so quickly from the first few tutorials. At this point you’ve learned how to make anything you can imagine just using a handful of the commands available in OpenSCAD.
But, what if you want to make use of someone else’s (or your own!) work? Wouldn’t it be great if there was a simple command that let you import an existing design? Thankfully, there is!
Once you’ve designed a useful object in OpenSCAD, there’s no need to copy and paste that code into new designs every time you want to use it. I’m going to show you a very simple command that will allow you to painlessly include those designs from other files. I’m also going to show you how to easily import an existing STL file into OpenSCAD for you to mashup to your heart’s desire.
Thingiverse citizen Coasterman turned in his homework after one of the last tutorials, so I’m going to use his hard work as an example in today’s tutorial. You can see a Thingiverse rendering of his work above!
- Including an OpenSCAD file is as easy as it sounds. For this example we’ll use Coasterman’s tutorial homework. If you’re playing along at home, be sure and download the appropriate file. Just drop the file into the same folder as your OpenSCAD program, type in the following command, and then hit “F5.”
- “include <Part 1 – Plus on Pedestal.scad>”
- You should see a shape like that above.
- As long as the file you’re importing was written properly, there’s no need to end that line with a semicolon.
- The “include” function is very useful for using someone else’s OpenSCAD code. When people have created useful pieces of OpenSCAD code, it’s called a “library.” We’ll learn how to use these in later tutorials.
- That’s about it! If you need two copies of something from a particular, just include the file twice. Just remember, that both copies will be placed in the exact same coordinates unless you move one or both of them.
- If you want to import an STL file into OpenSCAD, it’s about as easy as including an OpenSCAD file. So far I’ve been using quote marks to set apart the code examples. Since you need to include quotes (bolded for emphasis) within the line of code itself, I’ve switched to single quotes. As before, just drop the file into your OpenSCAD folder, copy and paste this command, and hit “F5.”
- ‘import_stl(“Plus on Pedestal.stl“);’
- Unlike the “include” command, we’ll need to finish that line of code with a semicolon.
- As with the “include” command, if you want two copies of that object, just enter that command twice. Again, both copies will be placed in the exact same coordinates unless you move one or both of them.
- I’m not sure that “chaining” is an official term (it probably isn’t), but that’s how I think of using multiple commands in a row. We’ve already learned how to manipulating simple forms by using the translate, rotate and scale commands. The cool thing is that these commands are just as easy when you’re manipulating a complex form. The upshot is that if you have learned how to manipulate a form and how to import an STL, you’re ready to build your own mashup!
- Let’s start slowly by taking the STL file above and try to manipulate it with translate, rotate, and scale.
- ‘translate([0,0,10]) import_stl(“Plus on Pedestal.stl“);’
- ‘rotate([45,0,0]) import_stl(“Plus on Pedestal.stl“);’
- ‘scale([2,2,2]) import_stl(“Plus on Pedestal.stl“);’
- Now, let’s get wacky. Let’s translate, rotate and scale at the same time:
- ‘translate([0,0,10]) rotate([45,0,0]) scale([2,2,2]) import_stl(“Plus on Pedestal.stl“);’
- The only thing to remember about “chaining” is that the commands will be run in reverse order. Here the STL would be imported, then it would be scaled 200% in the XYZ directions, then it would be rotated 45 degrees on the X axis, then translated 10mm along the Z axis.
- You can even use difference, intersection, and union commandson an imported STL. Let’s create a rectangular box and start mixing things up.
- First, let’s subtract the rectangular box from Coasterman’s homework:
- Now, the intersection of the rectangular box and Coasterman’s homework:
- And, we can put them together with the union function as well:
Using just one of the commands from today, “import_stl,” and what you’ve already learned in the prior tutorials you now have the knowledge and capabilities to remix anything on Thingiverse. I only threw the “include” command in there because it was easy to learn at the same time.
Think about it – using the difference command you can slice any model on Thingiverse and use the union command to stick an octopus on it. If their sizes are too different, well, just shrink the octopus using the scale function. All of Thingiverse lays before you.
Use what you’ve learned today to remix two existing STL’s from Thingiverse and then upload. Just as in school, it’s important to show your work. If you want to make me extra proud, please tag it with “openscadtutorial.” That way anyone who clicks that link will be able to see all of our hard work! As great big huge bonus, there’s a mashup challenge going on right now. You can do your homework for this tutorial and enter the challenge just by adding the tag, “mashmeup” to your Thing.
Bonus Section 1: The Tutorials So Far
Bonus Section 2: Other sources
If you like reading ahead or want more information about OpenSCAD, I’ve found these three websites to be very helpful. A word of warning, as much useful information is on these sites, I found the presentation to be confusing.
- Official OpenSCAD website
- OpenSCAD User’s Manual
- OpenSCAD beginner’s tutorial
- OpenSCAD tutorial roundup on the Thingiverse blog
Bonus Section 3: What’s next???
The topic of the next tutorial is up to you. What would you like to learn next? Do you want to know how to make helices? I’ve purposefully kept away from the programming stuff so far. Do you want me to get into some of that stuff? Is there something in particular you want to learn how to make in OpenSCAD? Leave a comment or shoot me an e-mail to me know!