Project 06 / 09

AI Detailing

A local-network service that reads a 2D progressive-die assembly drawing, rebuilds every manufactured part as a 2.5D model, and draws the company-standard detail prints for it, without AutoCAD. The same models also become a 3D assembly with a clash check, and a sister pipeline turns SOLIDWORKS 3D models straight into prints.

  • Python (FastAPI, ezdxf, Matplotlib)
  • FreeCAD / OpenCASCADE
  • ODA File Converter
  • SQLite
  • JavaScript (three.js)
  • C# (AutoCAD .NET)
  • Codex CLI
  • LM Studio
809,328
lines of code
193
historical dies run, 0 crashes
98 %
precision on the best die
1,944 / 1,944
eligible parts rebuilt as 3D solids

At a glance

Hand-written code 809,328 lines in 2,998 files
Test suite 1,385 test files, ~10,190 test functions
Benchmark corpus 14 development dies with golden part models, plus 1 held-out die never used for tuning
Real-world batch 193 historical die designs run end to end, 0 crashes
Best die (DK2204) 93 % feature recall, 98 % precision; 30 of 32 prints judged acceptable by the user (94 %)
3D rebuild 1,944 of 1,944 eligible parts solidified across 14 dies; every assembly STEP verifies
Server API FastAPI, 22 endpoints, SQLite job store, live progress stream

Lines of code by language

Language Lines Files
Python 804,196 2,975
JavaScript 2,055 7
HTML 1,182 4
C# 836 5
PowerShell 614 5
CSS 445 2
Total 809,328 2,998

Lines of code by area

Area Lines Files What it is
server 313,973 669 FastAPI service, job store, CAD adapters, standards matcher, AI runner, first-generation assembly pipeline
tests 277,802 1,385 Unit, API and real-CAD pipeline tests
scripts 101,255 699 Batch runners, scorers, audits, integration and proof scripts
sw2d 45,839 98 SOLIDWORKS 3D model → company prints
detailer 36,783 79 Second-generation reconstruction and drawing engine
detailer3d 29,418 47 2.5D part models → 3D solids, assembly STEP and clash check
web 2,798 10 Dependency-free upload UI and three.js assembly viewer
addin 836 5 AutoCAD add-in for reviewing AI drafts
root 624 6 Setup, launch and CLI scripts

Not counted: frozen code snapshots kept for benchmarking, vendored three.js, the ODA converter, virtual environments, job data and Markdown documentation.


The problem

After a progressive die is designed, a detailer pulls every manufactured part (plates, inserts, punches, backups, strippers) out of the assembly and draws it on its own sheet: the views, every hole with its size, depth, thread and side, a hole chart, the title block and tag. A die can have 30 to 400 of these details. It is skilled, repetitive work, and most of what goes on each print is already implied by the assembly. It just has to be reasoned out the way a detailer would.

 DieDesign 2D assembly (DWG) ──► Reconstruct (tiers 1–4) ──► 2.5D part models ──┬──► Draw ──► company detail prints (DWG)
   plan · elevation · sections      segment · correspond                          │
                                    defaults · mating                             └──► 3D solids ──► assembly STEP + clash check

 SOLIDWORKS 3D assembly ──► STEP + facts.json per part ──► sw2d ──► same part model ──► same Draw back end

What I built

1. Reconstruction: reasoning like a detailer

Each part becomes a PartModel (outline, thickness, and features with type, size, position, depth, through/blind and side). Every field carries its value, source tier, confidence and evidence, so a print can list exactly what was inferred and what needs checking. Reconstruction climbs a four-tier ladder:

  • Tier 1, segmentation: closed loops per CAD layer become part outlines; company hole blocks are decoded from a registry built from the CAD library and its plan-view block spreadsheet (block name and scale encode the hole size).
  • Tier 2, cross-view correspondence: plan, elevation and section frames are registered, and features are matched across views to recover thickness, steps, depths and through/blind.
  • Tier 3, die-design defaults: a rules file of shop conventions and catalog tables (tap drills, counterbore sizes, dowel fits, screw depths).
  • Tier 4, mating-part constraints: pockets match their inserts, screws imply tapped holes in the next plate, dowels go through both parts, backups follow their punches.

Facts no tier supports (material, heat treat, tolerances, approvals) are reported, never invented.

2. Drawing: company-standard prints

  • Projects plan, side and bottom views, and adds a section wherever one is needed to show a depth.
  • Writes hole charts that merge like sizes, dimensions, the tag1 / ltag detail tags and the 14-field title block on adaptive B/C/D/E company borders.
  • Details-in mode: when the designer has already pulled parts out onto tagged sheets, the pipeline keeps their numbering, BOM and balloons exactly as drawn. It fills in the depths, threads and counterbores from the assembly sheets and redraws each part on the same sheet number, so the BOM and sheet markers stay consistent.
  • Every output goes through a DXF → DWG → DXF round trip and is rejected if a required block, attribute or table changed.

3. 3D assembly and clash check (detailer3d)

  • Turns each 2.5D part model into a FreeCAD/OpenCASCADE solid and places it from its plan position and the z-extent read off the sections.
  • Writes an assembly STEP for review, quoting and CAM.
  • Checks the stack in 3D and catches errors the 2D prints hide: holes that don't line up through plates, screws without a tap, inserts that don't fit their pockets, and interferences.

4. SOLIDWORKS → prints (sw2d)

The Mursix Design Assistant add-in builds the die in 3D and knows every hole it cut. sw2d reads its STEP-plus-facts export, builds the same part model from the B-rep (with hidden-line removal and section cutting in OpenCASCADE), and hands it to the same drawing back end. Here nothing has to be inferred. The goal is views within .0005 in of the true projection, checked by an independent verifier that reads only the finished DWG and the STEP.

5. Service and web UI

  • AutoCAD-free toolchain: the ODA File Converter for DWG ↔ DXF, ezdxf for reading and editing, Matplotlib for sheet renders, FreeCAD for STEP.
  • Job pipeline: uploads are hashed and immutable, each job gets isolated input/work/output folders, and the job store is SQLite in WAL mode with a server-sent-event progress stream, cancel/retry, restart recovery and a stale-job reaper for workers that die mid-job.
  • Standards library: approved company drawings are converted, inventoried and ranked, and only the best one to three are given to a job as references.
  • AI where it helps: the Codex CLI runs a sandboxed detailing pass on individual details, with deterministic CAD checks as a visual-QA preflight and a second correction pass only for failures it can fix. If Codex is unavailable, a local model through LM Studio takes over with the same tools, and that job is always forced to human review.
  • Exact-result cache: keyed on the uploads, standards, configuration, rules and server code, so a rule change can never reuse a stale drawing.
  • AutoCAD review add-in (C#): the web UI's Review button opens the AI draft in AutoCAD for a designer to accept or correct.

6. Measurement first

  • Golden models: for each benchmark die, a ground-truth part model is extracted from the human-drawn detail package. It is used only for scoring; nothing is ever copied from it into the output.
  • Derivability audit: every golden feature is classified by which tier (if any) can recover it from the assembly, so recall is judged against what is actually derivable.
  • Scorer: recall, precision, feature kind, size, depth, outline and thickness, per part and per die, plus side-by-side renders against the human sheets.
  • Ablations: every rule change is run on and off across the corpus before it ships.

Results

Development dies (assembly in, prints out)

Die Parts Features Recall Precision Size Depth Derivable recall
DK2204 31 275 0.93 0.98 0.87 0.95 0.99
BW2109 35 440 0.80 0.93 0.88 0.95 0.94
BW2207 56 813 0.70 0.93 0.82 0.90 0.96
BW2202 105 1,562 0.73 0.93 0.83 0.96 0.95
NE2604 159 1,707 0.68 0.89 0.89 0.98 0.88
AE2101 401 3,286 0.63 0.88 0.91 0.94 0.89

Across all 14 development dies (~24,000 features): feature-weighted recall 0.65, mean derivable recall 0.78, precision 0.82–0.98.

  • User review on DK2204: 30 of 32 prints judged "accept with minor touch-up" (94 %), up from 84 % in the first review.
  • Takeaway: precision is high everywhere, so the engine rarely draws a wrong feature. Recall falls on the large dies, where much of what the human drew isn't derivable from the assembly at all.

Real designs (designer detail sheets in, dimensioned prints out)

193 historical die designs, run unattended:

Mean Median
Recall 0.91 0.98
Precision 0.96 0.98
Feature kind 0.94 0.94
Size 0.87 0.89
Depth 0.64 0.70

183 processed, 0 failed; the other 10 weren't recognized as designer detail sheets. The most common disagreements are which side a counterbore or tap is called from, and number-size callouts (#10-32) written as decimals.

3D assembly

Across 14 dies and 2,301 parts: all 1,944 eligible parts solidified, 1,753 placed in the assembly, and all 14 assembly STEPs verify. 81 % of same-half contacts check out as drawn.


Status

  • Working: the web service and job pipeline, the reconstruction and drawing engine, details-in mode, the 3D assembly builder and the benchmark/scoring harness.
  • In progress:
    • recall on large dies, depth accuracy, and callout side and number-size wording;
    • sw2d on its first full die (89 parts);
    • folding the new engine into the web UI's main Process flow, which still routes assemblies through review.
  • By design: every output is an engineering-review deliverable. The service makes a best defensible attempt and never certifies a print.