OpenSCAD Language Reference — PrintPal Docs

OpenSCAD Language Reference — PrintPal Docs

OpenSCAD's language is small — a few dozen keywords and a handful of rules. This page covers them in order: variables and values, vectors and lists, conditionals and loops, list comprehensions, and the special $ -prefixed variables that control rendering quality and the viewport.

Whitespace and newlines are insignificant. Statements end with ; ; module/function definitions and transformation blocks end with } (no semicolon).

OpenSCAD has six value types:

Assignment looks normal but has one trap: variables are statically scoped and the last assignment in a block wins, no matter where it appears. There is no runtime mutation.

i = i + 1; inside a for body re-binds i for the rest of the parsing scope — not for "the next iteration". Use a list comprehension or recursive function instead.

Vectors and lists are the same type — an ordered collection that may hold mixed types. Index with v[i] . Vectors of length 2–4 also support dot notation:

A range [start : step : end] is its own value type — primarily used in for loops and list comprehensions. The step is optional; ranges are inclusive of both endpoints when possible.

for creates a copy of its body per iteration and unions them. To intersect iterations instead (rarely needed but very powerful), use intersection_for .

Comprehensions are the idiomatic way to compute lists of points, sizes, or positions. They are pure expressions (return a list) — use them everywhere you would write a small data pipeline in another language.

let introduces a scoped binding — useful inside comprehensions and inside transformation chains.

Dollar-prefixed names are dynamically scoped — they pass into children automatically. Use them to control facet resolution, animation time, and the viewport.

Most parts look great at $fn=64 ; bump to 128 for showcase renders, drop to 32 while iterating to keep the preview snappy. The AI CAD agent picks a sensible default and lets you override per-call.

Use str() to build strings; chr() / ord() for code points; search() for substrings.

Send a prompt to the AI CAD agent and watch it write idiomatic OpenSCAD — variables at the top, named modules, parametric loops, and assertions for printability.

Recommended articles