An AST evaluator for the OpenSCAD language, producing Manifold CSG geometry from a parsed AST.
Project description
openscad_evaluator
An AST evaluator for the OpenSCAD language, producing Manifold CSG geometry from a parsed AST.
Overview
openscad_evaluator takes an OpenSCAD AST — as produced by
openscad_lalr_parser — and walks it to
produce Manifold meshes: a two-pass resolve (AST walk,
no CSG calls) then generate (bottom-up Manifold/CrossSection construction) pipeline, with
$fn/$fa/$fs, full built-in coverage (primitives, transforms, boolean ops, 2D geometry,
text(), surface(), DXF/3MF import, roof()), and a content-hash geometry cache
(ManifoldCache) so repeated renders/debugger pauses skip unchanged Manifold work.
It's GUI- and toolkit-agnostic: the only way it talks back to a caller is a handful of optional
callback parameters on Evaluator.__init__ (echo_fn, debug_hook, error_break_fn,
return_hook) — no QObject, no signals, no direct rendering. This is the evaluator that powers
BelfrySCAD.
See docs/evaluator.md for the full architecture reference: scope
processing, assignment order, the built-ins table, 2D/3D geometry handling, error format,
$variables scoping, include/use, and the Manifold provenance / AST-to-geometry-ID mapping
used for WYSIWYG picking.
Installation
pip install openscad-evaluator
For DXF import support:
pip install openscad-evaluator[dxf]
STL/OBJ/OFF/3MF export needs nothing extra -- all four writers are pure Python (export.py; 3MF
is just a ZIP of XML, built with the standard library's zipfile/xml.etree.ElementTree, not the
platform-limited lib3mf).
From Source
git clone https://github.com/BelfrySCAD/openscad_evaluator.git
cd openscad_evaluator
pip install -e ".[dev]"
Quick Start
from openscad_lalr_parser import getASTfromString, build_scopes
from openscad_evaluator import Evaluator
nodes = getASTfromString("cube([10, 10, 10]);")
root_scope = build_scopes(nodes)
ev = Evaluator()
bodies, id_to_node = ev.evaluate(nodes, root_scope)
for body in bodies:
print(body.body.num_tri(), "triangles")
Command Line
Installing the package also installs an openscad-evaluator script that evaluates a .scad file
and exports the result -- STL, OBJ, OFF, or 3MF, inferred from -o's extension:
openscad-evaluator model.scad -o model.stl
openscad-evaluator model.scad -o model.3mf
openscad-evaluator model.scad -o model.mesh --format obj # explicit format overrides the extension
echo()/warning output goes to stdout; a parse or evaluation error goes to stderr and exits
non-zero.
--debug drops into a small, gdb-style interactive debugger instead of running straight through:
set breakpoints and run, then step/next/finish/continue, print <name>, backtrace, and
set <name>=<value> to override a variable before resuming.
$ openscad-evaluator model.scad -o model.stl --debug
Reading symbols from model.scad...
(scad-dbg) break 12
Breakpoint set at model.scad:12
(scad-dbg) run
Breakpoint hit at model.scad:12
10 module bracket(w) {
11 h = w * 2;
-> 12 cube([w, h, 3]);
13 }
(scad-dbg) print h
$1 = 20
(scad-dbg) continue
Exported to model.stl
See src/openscad_evaluator/_debug_repl.py for the full command list (help at either prompt also
prints it), and examples/minimal_debugger.py for the underlying debug_hook protocol if you're
integrating your own debugger rather than using this one.
Examples
Runnable, self-checking scripts under examples/ go beyond the Quick Start above to
cover the two optional integration points most callers ask about:
examples/minimal_debugger.py— hooking a debugger intoEvaluator(debug_hook=...): tracing every statement, stopping evaluation at a breakpoint, and overriding a variable's value mid-run via the hook'smodsreturn value.examples/manifold_cache_reuse.py— sharing oneManifoldCacheacross repeatedevaluate()calls so an unchanged subtree (e.g. everything but the part of the script a user just edited) skips re-running Manifold work on the next render.
python examples/minimal_debugger.py
python examples/manifold_cache_reuse.py
Both are also run under pytest (tests/test_examples.py) so they fail CI if they drift out of
sync with the real API.
Development
uv sync --all-extras
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openscad_evaluator-1.1.0.tar.gz.
File metadata
- Download URL: openscad_evaluator-1.1.0.tar.gz
- Upload date:
- Size: 281.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f38e871a645811874875021ec78a509b68d7c98560f8fafa669d1ae9666a902
|
|
| MD5 |
1b9eb1161000b460e7ac672407f2470c
|
|
| BLAKE2b-256 |
5ebd0ef8ac41b28760564c63ee08099cc4e41c64fcf7e051c47217b296c90551
|
Provenance
The following attestation bundles were made for openscad_evaluator-1.1.0.tar.gz:
Publisher:
publish.yml on BelfrySCAD/openscad_evaluator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openscad_evaluator-1.1.0.tar.gz -
Subject digest:
1f38e871a645811874875021ec78a509b68d7c98560f8fafa669d1ae9666a902 - Sigstore transparency entry: 2204921593
- Sigstore integration time:
-
Permalink:
BelfrySCAD/openscad_evaluator@08d0f6b7d1cc6bff797c1b794e47b86c99640ca7 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/BelfrySCAD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08d0f6b7d1cc6bff797c1b794e47b86c99640ca7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file openscad_evaluator-1.1.0-py3-none-any.whl.
File metadata
- Download URL: openscad_evaluator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 282.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27fa7c4a95aefe67044da687b8844edea37160a15ea147fb4700694abd1aad25
|
|
| MD5 |
edfeef4abb4982dd8c48f91aabe57913
|
|
| BLAKE2b-256 |
4eec9e54f174fc0d02e81fa57f52db4dfb8d739e05f02c5d9aeb8143e26f6f0a
|
Provenance
The following attestation bundles were made for openscad_evaluator-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on BelfrySCAD/openscad_evaluator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openscad_evaluator-1.1.0-py3-none-any.whl -
Subject digest:
27fa7c4a95aefe67044da687b8844edea37160a15ea147fb4700694abd1aad25 - Sigstore transparency entry: 2204921633
- Sigstore integration time:
-
Permalink:
BelfrySCAD/openscad_evaluator@08d0f6b7d1cc6bff797c1b794e47b86c99640ca7 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/BelfrySCAD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08d0f6b7d1cc6bff797c1b794e47b86c99640ca7 -
Trigger Event:
release
-
Statement type: