The translator now emits native sketch constraints (auto mode): every HistCAD entry maps to a constrain_* call tagged with its source identity (constraint_id='h7_Distance'), variadic chains decompose with suffixed ids, and value_exprs evaluate through a unit-aware expression parser (mm/in/cm/m/ft/yd plus arithmetic and mixed-unit sums like '61.5 in + 8ft'). Stability comes from an honest dual path per feature: entities bind to s_geo, constraints derive s, promotion tries the constrained sketch and falls back to the geometry prefix when the solver reports conflict. The except branch re-inspects with strict=False and records WHICH constraint entries failed into SKETCH_CONFLICTS — the pipeline doubles as a dataset constraint-quality auditor (rounded coordinates vs over-determined systems are the observed conflict source). Sampled auto-mode results (volume still machine-exact on passes): - DeepCAD 100: 83 pass, sketch-tier retention 92.1% (conflicts: Length 7, Distance 6, Diameter 2, Equal 1) - Fusion360 100: 67 pass, retention 66.2% (Distance dominates with 49 — its halfSpace signed-offset dialect needs side semantics work) Demo regenerated with 28 constraint calls, volume unchanged at 349.4558.
SimpleCADAPI Examples
Run examples from the repository root with uv run python <path>.
Generated artifacts are written to examples/out/, which is ignored by git.
Every formal single-script example emits three synchronized artifacts under examples/out/:
the canonical self-contained .scadpkg, an AP242 .step, and an editable
FreeCAD .FCStd. Single-solid products use @scad.part; assemblies use
@scad.assemble with explicit immutable definitions for every physical part or
nested assembly. Both downstream CAD files are translated from the same product
package, so they retain the same definition closure, evaluated geometry,
assembly instances, names, solved placements, materials, and available semantic
metadata.
tools/run_examples.py requires every formal single-script example to rewrite
and validate all three CAD artifacts. The split AP242/Gmsh workflow below is
run directly, one script per stage.
Examples
04_dimension_tolerance_chain.py—out/dimension_tolerance_chain/dimension_tolerance_chain.scadpkg08_constrained_sketch.py—out/constrained_sketch/constrained_sketch.scadpkg10_part_assembly.py—out/hydraulic_rod_assembly/hydraulic_rod_assembly.scadpkg11_external_reference_gear_train.py—out/external_reference_gear_train/nested_external_reference_gear_trains.scadpkg12_ap242_gmsh_volume_mesh/model.py—out/ap242_gmsh_volume_mesh/ap242_gmsh_bracket.scadpkg7ep_caplcd_enclosure.py—out/7ep_caplcd_enclosure/caplcd_enclosure_7ep.scadpkg16_compact_two_stage_planetary_reducer/—out/compact_two_stage_planetary_reducer/compact_two_stage_planetary_reducer.scadpkg20_integrated_bldc_joint_actuator/—out/integrated_bldc_joint_actuator/integrated_bldc_joint_actuator.scadpkg
Product Package Exporter And Translator Matrix
Build the canonical package once:
uv run python examples/12_ap242_gmsh_volume_mesh/model.py
Then run any downstream exporter or translator directly:
uv run python examples/12_ap242_gmsh_volume_mesh/export_fcstd.py
uv run python examples/12_ap242_gmsh_volume_mesh/export_step.py
uv run --extra gmsh python examples/12_ap242_gmsh_volume_mesh/export_stl.py
uv run --extra gmsh python examples/12_ap242_gmsh_volume_mesh/export_obj.py
uv run python examples/12_ap242_gmsh_volume_mesh/translate_freecad_script.py
uv run python examples/12_ap242_gmsh_volume_mesh/translate_fusion360_script.py
uv run python examples/12_ap242_gmsh_volume_mesh/translate_solidworks_script.py
The outputs are editable FreeCAD .FCStd, AP242 .step, triangulated .stl,
quad-preserving .obj, and standalone Python scripts for FreeCAD, Fusion 360,
and SolidWorks. Every command above reads the same .scadpkg directly.
FEM meshing consumes the STEP produced by export_step.py:
uv run --extra gmsh python examples/12_ap242_gmsh_volume_mesh/export_fem_mesh.py
It imports AP242 through Gmsh's OpenCASCADE kernel and writes a 3D .msh.