A high-level 3D modeling DSL and lossless STEP (ISO 10303-21) parser/serializer in MoonBit.

moon add gmlewis/step| Package | Contents |
|---|---|
| gmlewis/step | STEP entity core: Entity, RawEntity, EntityId, Ref, fmt_num, step_str. |
| gmlewis/step/cad | Modeling DSL, STEP/assembly/CSG writers, glTF and Blender backends, face queries. |
| gmlewis/step/parse | Part 21 tokenizer and parser. |
| gmlewis/step/repository, header, entities/* | Entity repository, HEADER section, typed entity families. |
| gmlewis/step/components/* | Parametric mechanical parts, mechanisms, and design families. |
| gmlewis/step/cli | Argument parsing and error-reporting helpers for programs. |
import {
"gmlewis/step/cad",
}
pkgtype(kind: "executable")///|
async fn main {
let design = @cad.Design::new(name="my-model")
.add(
@cad.Cuboid::new(20, 20, 20)
.with_name("base")
.with_color(@cad.Rgb::orange()),
)
.add(
@cad.CalibrationChamferBlock::new(10, 10, 5, chamfer_size_mm=1.0)
.with_name("top-part")
.translate(z=20),
)
design.write_step(Some("model.step"), checked=true)
}moon run .///|
test "fmt_num emits ISO 10303-21 reals" {
inspect(@step.fmt_num(2.0), content="2.0")
inspect(@step.fmt_num(0.25), content="0.25")
}@cad.bolt_circle(6, 22.0) // 6 centers at radius 22.0
@cad.grid_of_holes(3, 2, 20.0, 15.0) // centered, row-major centers
@cad.point_on_circle(10.0, 90.0) // one point at an angle
let profile = @cad.Profile2D::new(@cad.Profile2D::centered_circle(60.0))
.with_hole_at(0.0, 0.0, 20.0) // central bore
.with_bolt_circle(6, 22.0, 5.0, fit=@cad.Fit::Free) // radius 22, bore dia 5
let plate = @cad.ExtrudedProfile::new(profile.outer, 8.0, holes=profile.holes)| Format | Extension | run-example.sh | Library API | Contents |
|---|---|---|---|---|
| STEP (flat) | .step, .stp | default, -o part.step, --step part.step | write_step(), to_step_file() | Exact B-Rep; opens in CAD viewers and slicers. |
| STEP (assembly) | .step | — | to_assembly_step(), to_instanced_step_string() | AP214 product structure; instanced form shares one part definition. |
| STEP (CSG) | .step | — | to_csg_step(), write_csg_step() | Real CSG_SOLID / BOOLEAN_RESULT tree. |
| STEP (evaluated) | .step | --eval [path] | to_step_evaluated(), write_step_evaluated() | OCCT-trimmed B-Rep when the design has booleans; otherwise the flat B-Rep. |
| STL | .stl | -stl [path], -o part.stl | — | Binary triangulated mesh for printers; derived from STEP. |
| 3MF | .3mf | --3mf [path], -o part.3mf | — | OrcaSlicer-ready package derived from STEP. |
| PNG | .png | --png [path], -o part.png | — | Four-view preview (iso/top/front/side) derived from STEP. |
| glTF | .gltf | --gltf [path], -o scene.gltf | to_gltf(), to_gltf_file() | Z-up preview mesh for web viewers. |
| Blender scene | .blend | --blend [path], -o scene.blend | create_blender_file() | Editable scene with real booleans. |
| Blender Python | .py | --bpy [path], -o scene.py | to_blender_python(), write_blender_python() | Blender Python script. |
./run-example.sh --list # numbered and component examples
./run-example.sh 12 -o coil.step
./run-example.sh 12 -o coil.step -stl # no path: derives coil.stl
./run-example.sh 12 -o coil.step -stl mesh.stl # explicit STL path
./run-example.sh 12 --gltf # writes 12-bifilar-electromagnet.gltf
./run-example.sh 12 --help # example-specific parameters///|
async fn parse_example(step_text : String) -> Unit {
match @parse.parse_repository_from_string_result(step_text) {
@parse.ParseRepositoryResult::Ok(repo) => {
println("entities=" + repo.len().to_string())
println(repo.to_step_file())
}
@parse.ParseRepositoryResult::Err(info) =>
@cli.eprintln(@parse.format_step_parse_error(info))
}
}./test-all.sh # moon fmt, moon info, moon test
python3 scripts/validate_step.py part.step
python3 scripts/validate_step.py --no-mesh part.step # syntax/topology only
python3 scripts/validate_step.py --gmsh part.step # second meshermoon doc # static site into _build/doc/
moon doc --serve # ... served locally
moon ide doc 'Sketch2D::rounded_rect' # signature + doc for one symbol
moon ide doc 'Sketch2D' # a type and its methods
moon ide doc '' # every symbol in the package| Path | Contents |
|---|---|
| cad/ | Intent-based DSL, shape compilers, STEP writers, analysis, glTF/Blender backends. |
| entities/, parse/, repository/, header/ | STEP entity model, parser, repository, serializer. |
| cli/ | Argument parsing and error-reporting helpers. |
| components/ | Parametric parts, mechanisms, gears, assemblies, collision, catalogue, design-family API. |
| examples/ | Runnable example programs (examples/README.md). |
| tools/ | Inspection and STEP statistics utilities (tools/README.md). |
| scripts/ | Validation, rendering, and example-management harnesses. |
| tests/ | Cross-package integration tests. |
| docs/ | Architecture boundary notes. |
$ moon version --all
moon 0.1.20261126 (ccd306a 2026-11-26) ~/.moon/bin/moon
moonc v1.0.0-rc1+3c0520448 (2026-11-26) ~/.moon/bin/moonc
moonrun 0.1.20261126 (ccd306a 2026-11-26) ~/.moon/bin/moonrun
pub(all) struct EntityId {
value : Int
}pub struct RawEntity {
name : String
args : String
}pub struct UnknownEntity {
}fn fmt_num(n : Double) -> Stringfn get_version() -> Stringfn step_str(s : String) -> StringInstall
Download zipA high-level 3D modeling DSL and lossless STEP (ISO 10303-21) parser/serializer in MoonBit.