Skip to content

Variables and expressions

Variables

Variables live in the Parametric tab of the right sidebar, in the Numeric Variables section.

To create a variable, click Add, type a name and a value or expression and confirm. Examples:

width = 800
thickness = 15
inner_span = width - 2 * thickness

Names

  • Letters, digits and underscore (_), starting with a letter or an underscore: width, shelf_gap, _t1.
  • No spaces, accents or hyphens.
  • Each name is unique in the module (variables and form fields share the same names).

Bounds (min/max)

Each variable can have optional min and max bounds. An edit that takes the value outside the bounds is refused (“Value 1200 above maximum (1000)”), and the previous value is kept.

  • Bounds protect direct edits; they are not reapplied to existing values when you change the bounds themselves.
  • Variables computed from other variables are re-evaluated normally, even if the result goes past their bounds.

Delete

Click Delete variable. Expressions that used the variable then show an error.

Expression syntax

ModuleCAD uses its own safe, dependency-free evaluator. It accepts:

Element Examples
Numbers 15, 0.5, 1200
Variables width, door_count
Arithmetic +, -, *, /, ^ (power)
Parentheses (width - 30) / 2
Unary minus -thickness
Comparisons ==, !=, <, <=, >, >=
Functions see the table below

In expressions the decimal separator is always the point and measurements are always in millimetres, whatever the display unit.

Comparisons

A comparison is worth 1 when true and 0 when false, so it can be combined with arithmetic:

plinth_height * (has_plinth == 1)

Functions

Function Description Example
min(a, b, …) Smallest value (2 or more arguments) min(width, 1200)
max(a, b, …) Largest value (2 or more arguments) max(height, 300)
floor(x) Rounds down floor(width / 400)
ceil(x) Rounds up ceil(height / 350)
round(x) Rounds to the nearest integer round(span / 2)
abs(x) Absolute value abs(deviation)
clamp(x, min, max) Limits x to the range clamp(width, 300, 1200)
if(cond, then, else) Conditional if(door_count == 2, width / 2, width)

Function names only apply when followed by parentheses — a variable called min still works on its own.

Errors

  • Invalid expression — a syntax error or a variable that doesn’t exist.
  • Circular reference — a depends on b, which depends on a.
  • Division by zero and malformed numbers (1.2.3) are also refused.

An expression with an error keeps the part’s last valid value and shows the error in red under the field.

Binding part fields

Any Position, Rotation or Dimensions field of the Properties panel accepts an expression. When you type something that isn’t a plain number, the field becomes bound: it follows the expression, and the computed value appears next to it (= 770).

Binding target Notes
Width, height, depth The result must be greater than zero.
Position X, Y, Z Always on the world axes.
Rotation X, Y, Z In degrees.
A mate’s offset In the Mates panel or when creating the offset mate.

To remove the binding, type a plain number in the field.

When a variable changes, every bound field is recomputed and the mates are re-solved.

Example: a cabinet with a parametric width

Variable Expression
W 800
H 700
D 350
t 15
Part Field Expression
Left side Position X -W/2 + t/2
Right side Position X W/2 - t/2
Bottom and top Width W - 2*t
Back Width W

Changing W to 1000 resizes and repositions everything at once.

Variables in projects

In projects, the module’s internal variables are invisible. Whoever uses the module only answers the module form. Older modules, created before the form existed, show the raw list of numeric variables in the Parameters panel.