Skip to content

Add an optional single-part drawing workflow for STEP and notebooks - #97

Open
anzeivant wants to merge 10 commits into
PhySpace:devfrom
anzeivant:feat/dxf-exporter
Open

anzeivant wants to merge 10 commits into
PhySpace:devfrom
anzeivant:feat/dxf-exporter

Conversation

@anzeivant

Copy link
Copy Markdown

Summary

Add sca drawing, an optional single-part drawing workflow for STEP files and SimpleCADAPI notebooks. The workflow proposes a primary orientation, orthographic views, a section when supported by the geometry, model-bound dimensions, and a sheet. Agents can inspect the proposed declaration and its audit, edit the declaration, and replay it.

This builds on the section views and model-bound DIMENSION entities introduced in #95. The workflow reuses SheetPlan and the vector DXF builder. Existing declarative callers can continue to use the same entry point.

What reviewers can try

sca drawing --step part.step --plan-only --out part.dxf
sca drawing --step part.step --mode engineering --drawing-json part.drawing.json --out reviewed.dxf --pdf
sca drawing --notebook examples/dxf_exporter/stepped_mount.py --primary-view top --no-section --sheet A3 --set HOLE_DIAMETER=8 --set HOLE_PITCH=36 --out variant.dxf

The CLI uses the existing drawing extra. The optional polygonal hidden-line projection uses the verify extra. The packaged walkthrough in examples/dxf_exporter/README.md covers the default notebook, parameter overrides, and replay. Its annotated diameter changes from Ø6 H7 to Ø8 H7 and the hole spacing changes from 31 to 36 mm. The workflow checks each bound value against the model and the written DXF.

Implementation

  • Add a planning and replay layer under simplecadapi.dxf_engine.workflow, with machine-readable issues and metric drafting presets.
  • Bind notebook parameters through DRAWING_INTENT and report unresolved bindings. Measure extents on the physical solid when STEP includes presentation geometry.
  • Export editable DXF, a pixel-bounded PNG, and an optional true-scale vector PDF. Label polygonal projections as review output and keep dimensions tied to the original geometry.
  • Provide shared-layout seven-view inspection and overlays alongside engineering drawing modes.

Validation

  • Windows, Python 3.12, and the released 2.3.0.post1 native extension. The selected drawing, CLI, and skill tests produced 111 passes. Three Windows-specific failures reproduced against the unmodified release (line endings, a TOML path fixture, and a zsh fixture). The source distribution built successfully with the example and template data included.
  • On 12 paired cases with identical STEP geometry per pair, the new workflow produced 12 DXF/PNG pairs and the native fixed-declaration baseline produced 11. Exact HLR timed out on the complex screw under the test limit. Three completed same-declaration controls agreed on the DXF dimension values and labels.
  • In a separate run, eight official modeling examples produced DXF and previews on both sides. Six use explicit drawing bindings in copies of the notebooks, with 22 parameter dimensions checked across default and variant runs. The other two use the official notebook source directly with automatic planning.

The generated sheets support single-part review. Manufacturing requirements, tolerances, and fits come from explicit input. Layout and missing-dimension issues remain visible in the audit.

codex and others added 10 commits November 18, 2026 21:08
DECISION: Expose a protected view-building hook and share the vector DXF builder.

WHY (2026-11-18 drawing integration): The requested contribution should add a complete drawing workflow to SimpleCADAPI while using the same solver and entity writers. A duplicated planner and DXF renderer would diverge.

WHAT CHANGES: Direct SheetPlan rendering still uses the existing projection and PNG path. The workflow can supply cached geometry and generate the saved vectors separately.

Checked: Native drawing and workflow tests passed in the integrated checkout with the unchanged release C++ extension.

Co-Authored-By: OpenAI Codex <[email protected]>
DECISION: Integrate dxf-exporter as an optional workflow in the existing sca CLI.

WHY (2026-11-18 drawing integration): The user wants to produce and review drawings without assembling a full declaration for each part, and to carry design parameters into measured drawing annotations.

ALTERNATIVE CONSIDERED AND REJECTED: A standalone CLI and independent solver would duplicate package setup and nominal measurements.

WHAT CHANGES: Add automated planning, declared replay, inspection overlays, bounded previews and audited notebook parameter bindings. Polygonal review projection uses the existing verify extra.

Checked: Checkout-based tests, 7 paired example exports, and 4 native same-declaration controls. The Windows skill-path TOML test also fails against the original wheel and is outside this series.

Co-Authored-By: OpenAI Codex <[email protected]>
…ok replay

DECISION: Keep the example and verification sources reviewable in Git.

WHY (2026-11-18 drawing integration): Maintainers need a reproducible example that distinguishes workflow automation from geometry measured by the existing SDK and checks the extended paths. See design-docs/optional-drawing-workflow.md.

WHAT CHANGES: Add an editable part notebook, command examples, and tests for native dimensions, physical-solid extents, bounded A0 output, declared views, overlays and rejected parameter mismatches.

Checked: 111 selected upstream and new tests passed. One original Windows skill-path TOML test was reproduced against the release wheel and excluded from that result.

Co-Authored-By: OpenAI Codex <[email protected]>
DECISION: Include the two small drawing example files in the existing sdist allowlist.

WHY (2026-11-18 drawing integration): The linked notebook is the reproducible design-intent example, and the default sdist filter excludes this folder.

Checked: uv build --sdist succeeded. The archive contains the drawing CLI, template JSON, README and notebook and excludes the local native extension.

Co-Authored-By: OpenAI Codex <[email protected]>
…icit units

DECISION: Keep unitless Vars as non-length parameters until a drawing binding declares a unit.

WHY (2026-11-18 official notebook comparison): The flange, bracket and constrained-sketch notebooks could not finish because the drawing workflow assumed every Var had a Unit. Counts and ratios are legitimate notebook inputs; the sketch also uses legacy unitless lengths.

WHAT CHANGES: List dimensionless parameters without inventing lengths and accept explicit units on selected dimensionless values. Keep canonical millimetres in the ledger after a binding resolves.

Checked: Six original upstream notebooks, 24 drawing runs and 22 parameter measurements; 112 selected upstream and drawing tests passed.

Co-Authored-By: OpenAI Codex <[email protected]>
…rated render_plan doc

PROBLEM
CI failed on all Python versions with three repository rules: Chinese text under src/
(drawing_templates.json labels and review notes), a skill reference to
../../examples/dxf_exporter/README.md outside the skill tree, and docs/.../render_plan.md not
regenerated after render.py changed.

DECISION
Translate the template labels and review notes (same keys, options and sources), link the
example folder (directory links are accepted by the skill lint, like the other example links),
and regenerate the API page with tools/auto_docs_gen.py.

EVIDENCE
test_library_is_english, test_skill_lint, test_skill_build, test_auto_docs_gen pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PROBLEM
auto_drawing wrote <out>.drawing.json and <out>.plan.json only after write_engineering_sheet
returned. A rendering failure (e.g. a DIM_RENDER_MISMATCH raised by the read-back check) left
the reviewer with neither the declaration to fix and replay nor the plan saying what failed.

DECISION
Catch the rendering error, record it under the plan's "render" entry, write both files, then
re-raise so the CLI still reports the error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PROBLEM
With --layout compact a full section replaced the top or right view under the name "section";
notebook design-intent rows naming that view no longer resolved. Reproduced with the PR's own
example: `sca drawing --notebook examples/dxf_exporter/stepped_mount.py --layout compact`
failed with "LEDGE_THICKNESS: specify a declared view".

DECISION
The section is that view, cut: it keeps the replaced view's name. Section views are recognised
by their "section" entry, never by the name, so nothing else depends on it.

EVIDENCE
The example now draws (A3, top = full section, 6 dimensions); new test
test_compact_layout_section_keeps_the_replaced_view_for_design_intent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ansforms

PROBLEM
- export_sheet required a top-level layout, while the only layout the CLI writes is nested under
  "layout" in the inspection metadata, so --layout-json could not take the CLI's own output
  ("This exporter keeps DXF modelspace at 1:1").
- rigid_shape indexed rotation / translation_mm directly: a transform JSON without one of them
  raised KeyError, which the CLI does not catch, so users got a traceback.

DECISION
Unwrap the nested layout as export_view_previews already does; raise ValueError naming the
missing keys (the CLI turns it into its JSON error with exit code 2).

EVIDENCE
Both reproduced through the CLI before the fix; new tests
test_an_inspection_sheet_reuses_the_layout_the_cli_wrote and
test_a_transform_without_translation_is_a_clear_error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@NiJingzhe

Copy link
Copy Markdown
Collaborator

Thanks for this workflow, the plan/audit/replay loop is well thought out. I reviewed the PR, reproduced the findings below through the CLI, and pushed fixes for the blocking ones onto this branch (maintainer edits), together with a merge of current dev (it was 42 commits behind; it merges cleanly).

CI (all Python jobs failed on three repository rules), fixed in e6361e40:

  • test_library_is_english: dxf_engine/workflow/drawing_templates.json had Chinese labels and review notes under src/. I translated them, keeping the keys, options and sources unchanged. Please check that the wording keeps your intent.
  • test_skill_lint: references/workflows/engineering-drawing.md linked ../../../../examples/dxf_exporter/README.md, which lies outside the skill tree. It now links the example folder, which the lint accepts, like the other example links.
  • test_auto_docs_gen: render_plan.md was regenerated after the render.py change.

Bugs, each reproduced and then fixed with a regression test:

  1. Render failure lost the declaration and plan (a598eeb4). auto_drawing wrote .drawing.json and .plan.json only after rendering succeeded. Now the render error is recorded in the plan, both files are written, and the error is re-raised.
  2. The compact layout could not draw the example (ea0e6034). sca drawing --notebook examples/dxf_exporter/stepped_mount.py --layout compact failed with LEDGE_THICKNESS: specify a declared view, because the full section replaced top under the name section. The section now keeps the name of the view it replaces; section views are recognised by their section entry, not by name.
  3. --layout-json rejected the CLI's own output (de3ffdb2). The inspection metadata nests the layout under layout, which export_sheet did not unwrap ("This exporter keeps DXF modelspace at 1:1"). It now unwraps it, as export_view_previews already does.
  4. Incomplete transform JSON gave a traceback (de3ffdb2). rigid_shape raised KeyError on a missing translation_mm. It now raises a ValueError naming the missing key, which the CLI reports as JSON with exit code 2.

Not blocking; worth a follow-up:

  • PDF scale vs. ezdxf version (details.py ~190): the true-scale PDF/PNG correction assumes ezdxf 1.4.5 truncates page points, while pyproject allows ezdxf>=1.4.4. Pin the version, or detect the truncation instead of assuming it.
  • Split bores are not found (find_bores): it only accepts a full 2π REVERSED cylindrical face. Holes exported as two half-cylinders end up "unresolved", so their diameters and the section choice are lost.
  • Counts treated as lengths (parameter_value): unitless numbers are treated as mm lengths. That matches the SDK convention, but a count such as HOLE_COUNT = 4 named in DRAWING_INTENT would become a 4 mm expectation. Consider marking integer parameters non_length.
  • Repeated work in fit_sheet: it rebuilds the plan up to 10 times. Each attempt re-indexes the model and recomputes the removed section, and that section's HLR is recomputed too because the face compound is part of the projection cache key. Compute those once.
  • projected_bounds copies the solid (rigid_shape with copy=True) only to read a bounding box. A located shape gives the same bounds.
  • Duplicated bounds code: removed_section re-implements projected_bounds with a different box helper. Reuse the one function so the two extents cannot drift apart.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants