Convert Drawing to CAD
drawing_to_cadUse this when the reference for a part is a 2D engineering drawing PDF (orthographic views with dimensions), not a photo. Deterministic, no vision model: reads the vector linework (stroke width, dash) and positioned text; classifies visible / hidden / center / dimension / extension lines; reads the title block scale, units and projection symbol; identifies front / top / side views by projection alignment (third- or first-angle); ties dimension text to its lines (⌀, R, 4×, ±, THRU, depth). Dimension values win over measured lengths. Rebuilds the part as the view silhouette extruded by the depth an orthogonal view shows, or a turned part revolved from its half-silhouette, plus holes from ⌀ circles with THRU or hidden-line depth. Returns script — a .kcad.ts with role-named params (width, thickness, holeDia, hole1X, dia1, step1Length …) — and ledger, an assumption ledger where stated dimensions are visible, symmetry-derived positions inferred, defaults assumed and an unstated depth missing; a dimension that disagrees with the linework keeps its value and records the disagreement as an open fact. With verify (default) the script is evaluated, re-projected through the svg-drawing view stage and compared: fidelity.verdict is match | partial | mismatch | failed with per-axis extents, hole diameters and per-view silhouette IoU. Pass out to write the script and its <stem>.ledger.json (resolve open facts with resolve_assumptions, then set_param). A scanned (raster-only) page fails with reference.drawing.raster-only — use trace_from_image for those.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| out | No | Write the emitted script here (a .kcad.ts path); the ledger is written beside it as <stem>.ledger.json. | |
| page | No | 1-based page to read. Default 1. | |
| path | No | Path to the drawing PDF on the machine running kernelCAD. | |
| verify | No | Evaluate the rebuilt part and compare it with the drawing. Default true. | |
| pdfBase64 | No | The PDF inline, base64-encoded. Use this instead of `path` against a hosted kernelCAD server. | |
| projection | No | Override the projection angle read from the sheet (default: projection symbol or note, else third-angle). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| page | No | ||
| sheet | No | { widthMm, heightMm, scale: { text, sheetPerModel, source }, units, projection } read off the sheet. | |
| views | Yes | Identified orthographic views: { name, bboxMm, identifiedBy, label? }. | |
| ledger | Yes | Assumption ledger: { facts, unresolvedCount }; facts are visible / inferred / assumed / missing, disagreements recorded on the fact. | |
| params | Yes | Role-named params declared by the script: { name, value, description }. | |
| script | No | The emitted .kcad.ts source. | |
| fidelity | No | { verdict: match | partial | mismatch | failed, extents, holes, silhouettes, reasons } from evaluating and re-projecting the script. | |
| pageCount | No | ||
| ledgerPath | No | Where the ledger was written (when `out` was given); pass it to resolve_assumptions. | |
| scriptPath | No | Where the script was written (when `out` was given). | |
| diagnostics | Yes | ||
| reconstruction | No | { kind: extrude | revolve, profileView, axis, holeCount, extents }. |