Modules as Operators

A powerful and often ignored feature of Openscad is that modules can also behave as if they were operators, exactly like the translate()or color() operators. They do not create shapes on their own, but they modify the subsequent commands. post

Here I test my understanding by defining a poke operator that inserts its first geometry through all subsequent geometry.

poke() { cylinder(30, 0, 10, true); translate([0,0,0]) cube([40,40,3],true); translate([0,0,6]) cube([40,40,3],true); }

// HEIGHT 370

We define a module that expands its children, some children over and over to make the gap for the first child to pierce the remainder.

module poke () { children(0); for(i=[1:$children-1]) { difference() { children(i); scale(1.5) children(0); } } }