5.6 KiB
CAD Generator Contract
Use this reference when creating or editing STEP, DXF, STL, GLB/topology, or imported STEP sources.
Source Types
- A generated part is a Python file with a top-level zero-argument
gen_step()returning an envelope withshapeandstep_output. - A generated assembly is a Python file with a top-level zero-argument
gen_step()returning an envelope with either flatinstancesor recursivechildren, plusstep_output. - A generated part may also define
gen_dxf()returning an envelope withdocumentanddxf_output. - Imported STEP/STP entries are targeted directly with
gen_step_partorgen_step_assembly. - Direct imported parts intentionally have no Python generator; do not create placeholder generators for them.
- Helper modules may live alongside generators as long as they do not implement a generator contract.
Generator Rules
Each generator script should:
- Be runnable from the project environment.
- Not rely on the current working directory. Resolve local filesystem paths from
__file__. - Be idempotent and deterministic. Avoid timestamps, random identifiers, or nondeterministic ordering unless explicitly required by the design.
- Fail clearly when required inputs are missing. Exit non-zero and identify the missing path and failing generator.
- Keep generated output locations explicit in generator envelopes or direct STEP/STP CLI flags; do not rely on sibling output naming.
Part Envelopes
gen_step() for parts must return:
shape: abuild123d.Shapestep_output: relative path to the generated.stepoutput
Optional fields include:
export_stl: booleanstl_output: relative path to generated.stloutput when STL export is enabledstl_tolerance,stl_angular_toleranceglb_tolerance,glb_angular_toleranceskip_topology: for parts that should emit GLB without selector topology sidecars
gen_dxf() must return:
document: an object with a callablesaveas(...)dxf_output: relative path to generated.dxfoutput
Assembly Envelopes
gen_step() for assemblies must return:
- exactly one of
instancesorchildren step_output: relative path to generated.stepoutput
Flat instances remain supported for simple assemblies and backward compatibility. Each instance must define:
path: STEP/STP path relative to the assembly generator filename: selector-safe instance name containing only letters, numbers,.,_, or-transform: 16-number row-major transform
Recursive children define a semantic occurrence tree. Each node must define:
name: selector-safe instance name containing only letters, numbers,.,_, or-transform: 16-number row-major transform
Each child node may also define:
path: STEP/STP path relative to the assembly generator filechildren: non-empty list of child nodesuse_source_colors: boolean, defaulttrue; setfalsewhen the assembly should render that node with viewer default material settings instead of referenced source colors
Nodes with children are subassemblies. Nodes with path and no children are leaf component instances unless the path resolves to a generated assembly source, in which case that generated assembly is expanded as a subassembly root. Sibling name values must be unique at every level. Empty subassemblies, invalid names, absolute paths, backslash paths, and . path segments are rejected.
Flat instances may also define:
use_source_colors: boolean, defaulttrue; setfalsewhen the assembly should render that instance with viewer default material settings instead of the referenced STEP/GLB source colors
Assembly STEP generation resolves instance and child node paths relative to the generator file. The referenced STEP/STP file must exist. Generated assembly exports preserve recursive labels where possible, while viewer mesh composition still loads only descendant leaf GLB assets.
Imported STEP/STP Targets
Imported STEP/STP files are passed directly to the split STEP tools:
gen_step_part path/to/file.steptreats the target as an imported part.gen_step_assembly path/to/file.steptreats the target as an imported assembly.
Optional CLI flags for direct imported targets include:
--export-stl--stl-output--stl-tolerance,--stl-angular-tolerance--glb-tolerance,--glb-angular-tolerance--color--skip-topologyfor parts
These flags are not persisted. Pass them each time an imported STEP/STP file needs non-default generation settings.
Output Paths
Envelope output fields and CLI output fields:
- are relative to the owning Python script or direct STEP/STP target
- must use POSIX
/separators - must use the correct artifact suffix
- are resolved as file paths, not through a harness root
The host project may impose its own layout policy, such as keeping outputs under a models/ directory, but the CAD skill runtime does not hardcode that convention.
Generated Artifacts
STEP generation writes package-local render/reference artifacts for STEP-backed parts and assemblies:
.<step-filename>/model.glb.<step-filename>/topology.json.<step-filename>/topology.bin
Assemblies embed composition data in .<step-filename>/topology.json under assembly.root when linked source information is available. Imported STEP assemblies may also write .<step-filename>/components/*.glb native component assets for part-list rendering.
These generated artifacts are not source of truth and must not be hand-edited.
Generation tools write and overwrite current configured outputs. They do not delete stale outputs when paths change.