OpenSCAD Tutorial

Lesson 4 · Variables and Modules

Reuse a part with a module

A module is your own shape command. Its parameters have defaults, so spacer() works on its own, and spacer(h = 12) overrides only the height. Variables declared inside the module, like eps, stay inside it.

For values rather than shapes, use a function: function radius(d) = d / 2;.

Common mistake: trying to update a variable like a counter. total = 0; total = total + 5; does not add up; total becomes undef. Use new names, module or function parameters, or the loops in the next lesson.

Your task: keep the default spacer and add two more: spacer(h = 12) moved to x = 20, and spacer(outer_d = 18, inner_d = 8) moved to x = 42.

Loading the OpenSCAD editor…
Step 11 of 16