Files
make-cad/examples
NiJingzhe 48c77c2055 feat(histcad): pure training-data translation, tools under research/histjson
Generated sources carry the model only: the dual-path constraint fallback,
SKETCH_CONFLICTS/SKETCH_TIER_FALLBACKS audit globals and strict=False
inspection are gone from translated code. Tier decisions and conflict
auditing moved to translation time: auto mode solves each feature's
constrained sketch prefix in-process (preflight), emits sketch tier when it
solves AND reproduces the transcribed coordinates (max point move <= 1e-3,
the drift gate), otherwise transcribed geometry; diagnostics go to the
sidecar report (<case>.ftc.py.report.json).

Root causes found by the new histcad_conflicts.py residual analyzer and
fixed in the translator:
- point-pair H/V distances are directed: sign now taken from coordinates
  (the stored length is a magnitude) — was the top Fusion conflict source
- Tangent on arcs needs an endpoint selector: picked as the nearest shared
  junction with the other curve
- MajorRadius/MinorRadius store full axis lengths: halved to semi-axes
  (solver was stretching ellipses 2x)
- Horizontal/Vertical flat line lists map each line individually
- variadic Equal chains get per-pair constraint ids (duplicate-id crash)
- Coincident entries whose refs pooled onto the same point are elided:
  degenerate point-coincident equations made the solver Jacobian singular
  and showed exact-geometry sketches as conflicting

SDK: constrain_concentric_rsketch now accepts ellipse targets (backend
resolves the ellipse center point).

Validation (100-case samples, constraints=auto): Fusion360 72 pass,
sketch-tier retention 77.5% (conflicts: 19 diverged + 1 conflicting);
DeepCAD 83 pass, retention 85.0% (9 diverged, 0 solver-conflicting).
Demos regenerated, volumes reconcile to STEP. Purity pinned by
test/test_histcad_translation_output.py (9 tests). Full suite 1489 passed.
2026-09-04 14:28:49 +08:00
..

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.scadpkg
  • 08_constrained_sketch.py — out/constrained_sketch/constrained_sketch.scadpkg
  • 10_part_assembly.py — out/hydraulic_rod_assembly/hydraulic_rod_assembly.scadpkg
  • 11_external_reference_gear_train.py — out/external_reference_gear_train/nested_external_reference_gear_trains.scadpkg
  • 12_ap242_gmsh_volume_mesh/model.py — out/ap242_gmsh_volume_mesh/ap242_gmsh_bracket.scadpkg
  • 7ep_caplcd_enclosure.py — out/7ep_caplcd_enclosure/caplcd_enclosure_7ep.scadpkg
  • 16_compact_two_stage_planetary_reducer/ — out/compact_two_stage_planetary_reducer/compact_two_stage_planetary_reducer.scadpkg
  • 20_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.