Thursday, September 11, 2014

How to use Openscad (2): variables and modules for parametric designs

Part 2/5: Variable and parametric design

The previous part addressed the basics of Openscad. It relied mostly on "immediate values": we were providing dimensions as explicit numbers. If you want to tweak the design dimensions, then you need to parse the scad source code and fix the numbers all everywhere.

In fact "hard coded" numbers must be avoided. As opposed to "static" designs, parametric designs give the flexibility to tune the numbers very efficiently at one place only. The good point is that Openscad is one of the best tool to do so.

A larger mug by using the scale operator (from the "basic" tutorial).
This is still not parametric, as numbers are hard-coded (a bad practice).
See how the numbers in our mug design above depends on each other? If the cube is to be made taller for any reason, then the intersecting sphere and hollow cylinder must be tuned accordingly in the source code. And this is exactly something a computer can do better than us.

So let us first convert this design to a parametric version, i.e. a design that can be tweaked with a small set of parameters that all have a clear role (width, height and so).


How to use Openscad (1), tricks and tips to design a parametric 3D object

Part 1/5: Introduction to constructive solid geometry with Openscad

Some technical and non-technical people keep asking me how I create new designs. As often, after a few personal replies, I end up heading to the blog to share the answer as they keep asking for more.

Also, I long wanted to write a pragmatic and step-by-step introduction, howto and tutorial to Openscad. The idea is to help people even with no programming skills (mostly in this part) and to bring newcomers to a point that they can design their own 3D objects (part two). Interestingly, Vicariously, Openscad is very interesting to get a glimpse at what programming is because you get an immediate, visual feedback of your actions (even my mother, a former history teacher, was eventually able to get a clue at what my job was about). Once understood these concepts, it may be much easier to move to other languages.

Now, if only a few readers become "designers" by reading this I will be quite happy. If some people realize that programming is not that obscure I will be happy also. Meanwhile, I will have given a detailed answer to my friends and contacts!

A non-obvious GoPro mount of mine, that is fully customizable thanks to Openscad.
It looks complex, but it is still exclusively made of spheres, cylinders, and cubes with a few basic "joints".
A forthcoming last part will deal with the complex features of Openscad. This one is for people that either learn fast or for those that are already proficient with the usual features of Openscad.
  1. Introduction to constructive solid geometry with OpenSCAD
  2. Variables and modules for parametric designs
  3. Iteration, extrusion and useful parametrized CSG techniques
  4. Children, factorized placement and chained hulls

So first, what is Openscad? Within the CAD family, it is a 3D modeler: a software that helps you to create 3D objects. There are many such tools, but this one is used extensively in the 3D printing community, not only because it is free but because is it really efficient for some kind of objects.

It may or may not suit your mind, but with time I am able to "see" the shape I describe, not as text but directly as shapes. I guess it depends on people, but I am sure there are people that are not programmers that can think alike. And if you are already a programmer with no industrial goal then you really should give it a try. It will be a breeze to use up to a productive level, especially if you do not want to invest time in a new and hellish interactive user interface!

The official manual is OK but it does not really work as an introduction. The navigation is also sometimes difficult to the point google is more useful. There is a nice raw cheat sheet also but it has no link to the respective functions (what a pity!) (update: it does now!). In any case, these fail to help to learn Openscad quickly in my humble opinion.