With OpenScad http://www.openscad.org3D objects can be created a bit special since code has to be typed in and this will then be converted into a 3D object. This sounds a bit odd, however when creating precise technical things then it is a quite effective way.



Pressing F5 for compile or automatic reload and compile makes it appear as 3D. Moving the mouse while left pressing its button rotates the view around one axes. While doing that pressing the shift button rotates it around the other axis.

The above creates an object with two fake coins put together to be used on shopping mall carts (in Switzerland).

Some things in the code are not so obvious:

Figure 10.4. OpenScad


After Compile and Render using CGAL the work can be exported to STL and the mesh is really nice and clean (No manual mesh fixing as often necessary with other tools). OpenScad uses Constructive Solid Geometry (CSG) to create the objects and not Vertices, Edges and Faces. It can operate with primitive objects as cube, cylinders and so on. When the work is done it can convert it into a mesh file format that uses Vertices, Edges and Faces.

If some dimension after 3D printing is not ok, simply change the parameter value and the work is done.


There are two manuals that are not consistent the more complete one is and the one when clicking help in OpenScad

Splitting into different files

It is worth to split a design into different files as having all the values in on file or when creating an assembly that takes multiple parts from individual files:

include <hydroclip.scad>



There is include but also use. The difference is include runs the code and use not but gets the definitions.

The file hydroclip.scad being included needs a module definition as

module hydroclip(){ 
<add the commands here>

Libraries can be included as regular scad files without path information if there are in a place OpenScad looks into, as /usr/share/openscad/libraries/. But since the MCAD libraries are in a subdirectory the subdirectory must be added:

include <MCAD/gears.scad>

OpenScad libraries

When splitting the work to different files than it is worth to reuse the files also in other project. Therefore the files must be in a location that can be easily found. There are 3 ways where libraries can be found:

The installed library path /usr/share/openscad/libraries

The path per user at ~/.local/share/OpenSCAD/libraries

And finally the OPENSCADPATH environment variable that can contain more than one path.

OpenScad Hints

Rotation of the objects take the origin of the coordinate system and not the center of the objects. Therefore alway rotate the object first and then move (translate) it. This needs some discipline but removes the complexity of dealing with many coordinate systems.

Difference and object that already used difference seems to be critical when the result needs to be exported to stl for later 3D printing.

Extruding 2D to 3D

A strong feature is also extruding 2D to 3D. Not just linear extrusion is possible also rotation extrusion. There are also options as twist during extrusion.

Some advanced thing is the surface command that reads in a file that has a 2 dimensional array of different surface heights. One application would be using an image to emboss or impress it.


Variables are more like constants in OpenScad, since they can not easily be modified at runtime. To still modify them at runtime, the assign function must be used. Then a value can be assigned inside a block defined by the {} characters.

for (z = [0:3]){
  assign(angle = z*90 ){

There is also the key word function where a value can be passed and a result is returned:

      function headh(d)=screw_cyl[d][1]; 


Openscad allows to animate the 3D objects. The time ticks FPS can be specified using the gui. On every tick the 3D objects are calculated.

The special variable $t holds the time (value between 0 to 1) and can be used to create different pictures per tick (as translation, rotation). Steps holds how many pictures are created.

From a coding point of view something as

  <do what needs to be done when time is 0>

or simply animate


or to get more effect multiply $t.


The checkbox "Dump pictures" then creates png pictures for every step. Programs as gimp can then merge then into an animated gif.

Linurs Servernest startpage