Operators on Solids
PythonSCAD overloads Python operators on solid objects to provide concise syntax for common operations.
add
obj + vector -- Translate by displacement vector.
When both operands are lists/vectors, standard addition applies.
subtract
obj1 - obj2 -- Difference (subtract obj2 from obj1).
obj - [x, y, z] -- Translate by the negated vector.
from openscad import *
(cube(10) - sphere(7)).show()
(cube(5) - [10, 0, 0]).show() # same as translate by [-10, 0, 0]
multiply
obj * factor -- Scale uniformly.
obj * [x, y, z] -- Scale per axis.
or
obj1 | obj2 -- Union.
and
obj1 & obj2 -- Intersection.
matmul
obj @ matrix -- Apply a 4x4 transformation matrix (same as multmatrix).
xor
obj1 ^ obj2 -- Hull of two solids.
obj ^ [x, y, z] -- Explode with a vector.
mod
obj1 % obj2 -- Minkowski sum of two solids.
obj % [x, y, z] -- Rotate by vector.
unary
+obj -- Highlight (debug modifier, shown in translucent red).
-obj -- Background (debug modifier, shown as ghost).
~obj -- Only (show only this object, hide everything else).
These correspond to OpenSCAD's #, %, and ! modifier characters.
OpenSCAD reference: Modifier Characters