Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice
TypeScript 3d-modeling3d-printing3d-printing-toolsagentagentic-aiai-cadcadcadqueryclaude-codecodexelectronfemllmmacdmakeropencodeparametric-designpythonsteptext-to-cad
App: Skill und Test Zeichnungen nach dem ersten Agent-Test (E76)
Kai-Jungsthoefelb33c6cb4b2de
diff --git a/app/resources/skills/zeichnung.md b/app/resources/skills/zeichnung.mdindex 47f574b..6bc5c71 100644--- a/app/resources/skills/zeichnung.md+++ b/app/resources/skills/zeichnung.md@@ -65,14 +65,23 @@ sh.text("Deburr all edges", (30, 30))- `direction` can be a vector from the part to the viewer (auxiliary view of an inclined face), `up=` turns the view.- `style="phantom"`: adjacent parts and extreme positions as thin dash-double-dot lines. Give it the same `origin=`(a model point) and `at=` as the view it belongs to.+- Long parts (shafts, profiles, rails): `breaks=[(p1, p2)]` leaves out the part between two model points and draws+ break lines. Dimensions across the break show the full length. Give views in a row the same breaks.+- Labels soma places itself (view label, "A-A", the letters of a cutting line or detail) move with `label_at=`,+ `letters_at=[(x, y), (x, y)]` and `letter_at=` (sheet points) when they get in the way of dimensions.## Sections and details- Section where inner shape matters: bores, pockets, walls. `sh.section(what, direction, through=point, ...)` removeseverything between the viewer and the plane through `point`. `name="A"` with `parent=front` draws the cutting line,arrows and letters, and "A-A" above the section.-- Half section of a symmetric part or a local break-out: `region=` a solid that is removed (a box over one quarter).- Draw the border yourself: center line for a half section, thin freehand line for a break-out.+- Stepped section through features that do not lie in one plane: `path=[p1, p2, p3, ...]` (model points, seen in+ `parent`) instead of `through`. Everything on the viewer's side of the path is removed, the cutting line gets thick+ ends and bends. Half section: a path from outside to the axis and then towards the viewer, e.g.+ `path=[(-50, 0, 0), (0, 0, 0), (0, -50, 0)]`.+- Local break-out: `region=` a solid that is removed, without `parent`. Where a cut is seen edge-on (steps, the middle of+ a half section, the border of a break-out) soma draws no edge: add a center line (half section) or a thin freehand+ line (break-out) yourself.- Not cut along their axis (ISO 128-40): screws, nuts, washers, pins, shafts, keys, rolling elements, ribs. List themin `unhatched=`.- Hatching is 45° and alternates between neighbouring parts. Thin walls (under 2 mm on the sheet): `hatch="solid"`.@@ -81,8 +90,10 @@ sh.text("Deburr all edges", (30, 30))## Dimensions-- Never type a value: give model points, soma measures. `"<>"` in `text` is the measured value: `"Ø<> H7"`,- `"<> ±0.1"`, `"4x <>"`, `"(<>)"` for an auxiliary dimension. Typed numbers that differ from the model are reported.+- Never type a value: give model points, soma measures. `"<>"` in `text` is the measured value: `"<> ±0.1"`,+ `"4x <>"`, `"(<>)"` for an auxiliary dimension. Typed numbers that differ from the model are reported.+ `view.diameter()` and `view.radius()` add Ø and R themselves (`text="<> H7"` gives "Ø8 H7"), `"Ø<>"` is for a+ diameter dimensioned from the side with `view.dim()`.- Every feature is dimensioned once, in the view where it shows best. Dimension visible edges, not hidden ones. Pointslie on an edge or on a circle center of that view: on rounded or chamfered corners take a point on the straightedge, not the virtual corner.@@ -91,8 +102,11 @@ sh.text("Deburr all edges", (30, 30))- Small dimensions near the part, bigger ones outside: first line about 10 mm from the edge, then 7 to 8 mm steps(`offset`). Dimension lines do not cross each other, texts never sit on edges.- Diameters with `view.diameter(center, r)` where the hole is a circle, on a side view a linear dimension with- `"Ø<>"`. Radii with `view.radius(center, r)`. Patterns: one dimension `"4x <>"`, positions from a datum or the+ `"Ø<>"`. Radii with `view.radius(center, r)`. `angle=` is the direction from the center to the text (0 right, 90 up),+ pointing away from other dimensions and edges. Patterns: one dimension `"4x <>"`, positions from a datum or thepattern center, `view.center_marks()`.+- Positions that are not in the model (screws fitted later, holes drilled on assembly): mark them with+ `view.center_mark(point, r)` and dimension to its center. Dimensions may also end on a `view.centerline()`.- Threads: `"M5"` or `"M5 - 10 deep"` on the hole. soma models threads without the helix (tap drill or core), soalways name the thread. Through holes: `"Ø<> THRU"` or a leader.- Angles: `view.angle(vertex, p1, p2)` in views where both lines lie in the paper plane.@@ -113,8 +127,8 @@ sh.text("Deburr all edges", (30, 30))- Views of the assembly, often a section along the main axis with the screws unhatched. Only overall, connecting andfitting dimensions.-- Item numbers with `view.leader(point_on_part, "1", at=..., end="dot")`, lined up in a row or column, the same part- always gets the same number.+- Item numbers with `view.leader(point_on_part, "1", at=..., end="dot")`, lined up in a row or column next to the+ views and off the parts list, the same part always gets the same number.- Parts list with `sh.table(rows, at, widths)` on the title block: item, name, quantity, material or designation (forstandard parts the designation of `soma.fasteners`, e.g. "ISO 4762 M5x16").@@ -124,20 +138,23 @@ sh.text("Deburr all edges", (30, 30))VISIBLE (0.5 mm), THIN, CENTER, HIDDEN, PHANTOM, HATCH, CUT, DIM, TEXT, text style and dimension style "ISO". Ownezdxf dimensions in a view need `override={"dimlfac": 1 / view.scale}`.- `view.pt((x, y, z))` is the sheet point of a model point. Draw what soma does not offer yourself: surface and weld- symbols, datum triangles, break lines, a different title block.-- `sh.text(text, at, height=3.5, align=, rotation=)`, several lines with `\n`. Heights: 3.5 mm, view names 5 mm,- never under 2.5 mm.+ symbols, datum triangles, a different title block.+- `sh.text(text, at, height=3.5, align=, rotation=)`. Several lines with `\n`: the first line at `at`, the others below,+ leading spaces indent. Heights: 3.5 mm, view names 5 mm, never under 2.5 mm.## Build and check1. `soma drawing build` (or `soma drawing build drawings/x.py`). Errors name file and line. Warnings report texts on- edges or on each other, things outside the frame or on the title block, points on no edge, typed numbers that- differ from the model and uncommon scales. Fix them, or tell the user why one is fine.+ edges, on dimension, leader or cutting lines or on each other, things outside the frame or on the title block or a+ table, texts too long for their cell or title block field, points on no edge, typed numbers that differ from the+ model and uncommon scales. Fix them, or tell the user why one is fine.2. **Open the picture `.soma/drawings/<name>.png` and look at it.** It is large and gets scaled down when you open it:crop parts of it (Pillow is installed) to read small texts and check every dimension and hatching.3. `soma drawing info "Name"`: views with their place on the sheet, circles, every dimension with its value. Comparewith your plan: every feature dimensioned once, nothing crowded.-4. PDF and DXF are in `output/drawings/`. After model changes build the drawings again before you commit.+4. PDF and DXF are in `output/drawings/`, all sheets in one PDF in `output/drawings.pdf` (ordered by file name, then+ by their order in the file; written only when no drawing has errors). After model changes build the drawings again+ before you commit.## Feedbackdiff --git a/app/resources/template/AGENTS.md b/app/resources/template/AGENTS.mdindex 074956a..3d3dc68 100644--- a/app/resources/template/AGENTS.md+++ b/app/resources/template/AGENTS.md@@ -16,7 +16,7 @@ The app shows the result in a 3D viewer next to this terminal. Notes and wishes| `exports/` | Single-part exports written by `soma export` || `animations/` | Optional. Motion, camera flights and captions in Python (`soma.anim`), one file per topic. The skill for animation explains them || `analyses/` | Optional. Load cases for `soma analyze fem` in Python (`soma.fem`), one file per load case. The skill for FEM explains them |-| `drawings/` | Optional. Technical drawings in Python (`soma.drawing`), one file per drawing or set of sheets. `soma drawing build` writes PDF and DXF to `output/drawings/`. The skill for technical drawings explains them |+| `drawings/` | Optional. Technical drawings in Python (`soma.drawing`), one file per drawing or set of sheets. `soma drawing build` writes PDF and DXF to `output/drawings/`, all sheets together to `output/drawings.pdf`. The skill for technical drawings explains them || `renders/` | Pictures and videos written by `soma render`. Not in the version history and not in the saved ZIP || `.soma/` | App data (viewer cache, build status, feedback images, skills, built animations, analysis results, drawing pictures). Do not edit. Read the skills in `.soma/skills/` as the list at the end of this file says, and files in `.soma/feedback/` when the user points you to them |diff --git a/app/test/drawing.mjs b/app/test/drawing.mjsindex 09e7814..39b3433 100644--- a/app/test/drawing.mjs+++ b/app/test/drawing.mjs@@ -1,7 +1,9 @@// Test für technische Zeichnungen (soma.drawing, E76): Der Codeblock des Skills „Technical drawings“ baut ohne Hinweise,// Ansichten, Schnitt, Einzelheit und Maße landen als DXF, PDF und PNG, gleicher Inhalt gibt gleiche Dateien, die Prüfung// meldet getippte Zahlen, Punkte neben Kanten, verdeckte Kanten, Text außerhalb und übereinander, Fehler nennen Datei und-// Zeile. Dann in der echten App: die PDF öffnet im Code-Panel, Bild und PDF zählen nicht als ungespeicherte Änderung.+// Zeile. Die Rückmeldungen des ersten Agent-Tests (Blatt „Feedback“): Zahlen, Ø, Lage des Durchmessertexts, mehrzeiliger+// Text, Schriftfeld, Stückliste, verschiebbare Beschriftung, Stufenschnitt, unterbrochene Ansicht, Gesamt-PDF.+// Dann in der echten App: die PDF öffnet im Code-Panel, Bild und PDF zählen nicht als ungespeicherte Änderung.// Aufruf: npm run test:drawing (baut vorher). SMOKE_VISIBLE=offscreen SMOKE_SHOTS=1 legt ein Bild ab.import { spawnSync } from 'node:child_process';import fs from 'node:fs';@@ -42,6 +44,26 @@ sh.text("one again", (41, 40.5))sh.text("tiny", (40, 60), height=1.5)cut = sh.section(["Bracket", "Pin"], "front", through=(0, 0, 0), at=(150, 120), name="A", unhatched=["Pin"])b = sh.detail(front, (60, 0, 12), 5, at=(320, 120), scale="5:1", name="B")+sh.view("Bracket", "top", at=(330, 230), label="Top", label_at=(150, 188))+`;++// Rückmeldungen aus dem ersten Agent-Test: Zahlen ohne Nachkommastellen, kein doppeltes Ø, Text des Durchmessers in+// Richtung angle, eingerückter mehrzeiliger Text, Schriftfeld zu schmal, verschobene Beschriftung, Stufenschnitt mit+// Schnittverlauf, unterbrochene Ansicht, Maß auf ein Mittenkreuz ohne Bohrung, Positionsnummer in der Stückliste+const FEEDBACK = `from soma.drawing import Sheet, num+assert (num(130, 0), num(-0.0, 0), num(12.5)) == ("130", "0", "12.5"), num(130, 0)+sh = Sheet("Feedback", size="A3", scale="1:1", material="Birke Multiplex 18 mm")+top = sh.view("Bracket", "top", at=(100, 200), origin=(0, 0, 12))+top.diameter((0, 0, 12), 5, angle=90, text="Ø<> H7")+top.center_mark((20, -20, 12), 2.5)+top.dim((-60, -30, 12), (20, -20, 12), offset=-12)+sh.text("Notes:\\n 1. Deburr all edges, break sharp edges 0.3 x 45 degrees\\n 2. Anodize", (30, 280))+front = sh.view("Bracket", "front", at=(300, 230), breaks=[((-30, 0, 0), (30, 0, 0))], label="Shortened", label_at=(300, 255))+front.dim((-60, -30, 0), (60, -30, 0), offset=-10)+a = sh.section("Bracket", "front", path=[(-70, 17.5, 0), (-20, 17.5, 0), (-20, 0, 0), (70, 0, 0)], parent=top, name="A",+ at=(100, 110), letters_at=[(25, 225), (175, 225)])+sh.table([["1", "Bracket", "1"]], at=(230, 70), widths=[10, 40, 10])+top.leader((0, 0, 12), "1", at=(235, 65), end="dot")`;const BROKEN = `from soma.drawing import Sheet@@ -62,12 +84,15 @@ try {fs.writeFileSync(path.join(dir, 'drawings', 'skill.py'), block + '\n');fs.writeFileSync(path.join(dir, 'drawings', 'checks.py'), CHECKS);fs.writeFileSync(path.join(dir, 'drawings', 'broken.py'), BROKEN);+ fs.writeFileSync(path.join(dir, 'drawings', 'feedback.py'), FEEDBACK);const b1 = soma(dir, 'drawing', 'build', '--json');let res = null;try { res = JSON.parse(b1.stdout); } catch { /* unten gemeldet */ }- check('soma drawing build --json: zwei Blätter gebaut, ein Fehler, Rückgabe 1', !!res && res.built.length === 2 && res.errors.length === 1 && b1.status === 1,+ check('soma drawing build --json: drei Blätter gebaut, ein Fehler, Rückgabe 1', !!res && res.built.length === 3 && res.errors.length === 1 && b1.status === 1,(b1.stderr || b1.stdout).slice(-200));+ check('Gesamt-PDF wird bei einem Fehler nicht geschrieben (es fehlte ein Blatt)', res?.set?.skipped === true && !fs.existsSync(path.join(dir, 'output', 'drawings.pdf')),+ JSON.stringify(res?.set));const by = Object.fromEntries((res?.built ?? []).map((x) => [x.name, x]));const br = by.Bracket;check('Skill-Codeblock: Blatt "Bracket" mit 4 Ansichten (Vorder-, Draufsicht, Schnitt A-A, Einzelheit B) und ohne Hinweise',@@ -91,6 +116,43 @@ try {&& has(10, 'at least 2.5 mm') && has(2, 'Scale 1:3'), w.join(' | ').slice(0, 200));check('Keine Hinweise ohne Grund (Schnitt, Einzelheit, Gesamtmaß 120 an echten Kanten)', !w.some((m) => /^(3|11|12): /.test(m)),w.filter((m) => /^(3|11|12): /.test(m)).join(' | '));+ check('Prüfung: Ansichtstitel auf einem Maß, mit Hinweis auf label_at', has(13, 'Label "Top" lies on dimension') && has(13, 'label_at=(x, y)'),+ w.filter((m) => m.startsWith('13:')).join(' | '));++ const fb = by.Feedback;+ const fw = (fb?.warnings ?? []).map((x) => `${x.line}: ${x.message}`);+ const fhas = (line, part) => fw.some((m) => m.startsWith(`${line}: `) && m.includes(part));+ check('Schriftfeld: zu langer Werkstoff wird gemeldet', fhas(3, 'Title block: "Birke Multiplex 18 mm" does not fit the field Material'), fw.join(' | ').slice(0, 300));+ check('Positionsnummer in der Stückliste wird gemeldet (Text und Hinweislinie)', fhas(14, 'Text "1" overlaps the table of line 13') && fhas(14, 'The leader overlaps the table'),+ fw.join(' | ').slice(0, 300));+ check('Sonst keine Hinweise: Ø-Text frei, Maß auf das Mittenkreuz, mehrzeiliger Text im Rahmen, Stufenschnitt, unterbrochene Ansicht',+ !fw.some((m) => /^([4-9]|1[0-2]): /.test(m)), fw.filter((m) => /^([4-9]|1[0-2]): /.test(m)).join(' | '));+ check('Maße: Ø nicht doppelt ("Ø10 H7"), 80 bis zum Mittenkreuz, 120 über die Unterbrechung', ['"Ø10 H7"', '80', '120'].every((l) => fb?.dims.some((d) => d.label === l)),+ fb?.dims.map((d) => d.label).join(' '));+ const fbCheck = py(['-c', String.raw`+import json, sys, math, ezdxf+doc = ezdxf.readfile(sys.argv[1])+msp = doc.modelspace()+texts = [(t.dxf.text, tuple(round(v, 2) for v in t.dxf.align_point)[:2]) for t in msp.query("TEXT")]+dia = [d for d in msp.query("DIMENSION") if "H7" in d.dxf.text]+mt = [e for d in dia for e in d.virtual_entities() if e.dxftype() == "MTEXT"]+step = [l for l in msp.query("LINE[layer=='VISIBLE']") if abs(l.dxf.start.x - 80) < 0.01 and abs(l.dxf.end.x - 80) < 0.01 and 95 < l.dxf.start.y < 125]+print(json.dumps(dict(+ indent=any(t.startswith(" 1. Deburr") for t, _p in texts), mtext=len(msp.query("MTEXT")),+ dimtext=[d.dxf.text for d in dia], ø=[e.plain_text() for e in mt], up=[round(e.dxf.insert.y - 200, 2) for e in mt],+ letters=sorted(p for t, p in texts if t == "A"), label=[p for t, p in texts if t == "Shortened"],+ breaks=len([p for p in msp.query("LWPOLYLINE[layer=='THIN']") if len(p) == 6]),+ cut=[len(p) for p in msp.query("LWPOLYLINE[layer=='CUT']")], step=len(step))))+`, path.join(dir, 'output', 'drawings', 'Feedback.dxf')]);+ let fx = null;+ try { fx = JSON.parse(fbCheck.stdout); } catch { /* unten */ }+ check('Mehrzeiliger Text als Zeilen (kein MTEXT), Einrückung bleibt', fx?.indent === true && fx.mtext === 0, (fbCheck.stderr || fbCheck.stdout).slice(-200));+ check('Durchmesser: "Ø<> H7" wird "Ø10 H7", der Text steht in Richtung angle=90 (über der Mitte)', fx?.dimtext?.[0] === '<> H7' && fx.ø[0] === 'Ø10 H7' && fx.up[0] > 5,+ JSON.stringify(fx && { dimtext: fx.dimtext, ø: fx.ø, up: fx.up }));+ check('Buchstaben des Schnittverlaufs an letters_at, Titel an label_at', JSON.stringify(fx?.letters) === '[[25,225],[175,225]]' && JSON.stringify(fx?.label) === '[[300,255]]',+ JSON.stringify(fx && { letters: fx.letters, label: fx.label }));+ check('Stufenschnitt: Schnittverlauf mit 4 Punkten und zwei dicken Knicken, keine Kante an der Stufe; zwei Bruchlinien', JSON.stringify(fx?.cut) === '[4,3,3]' && fx.step === 0 && fx.breaks === 2,+ JSON.stringify(fx && { cut: fx.cut, step: fx.step, breaks: fx.breaks }));const err = res?.errors[0];check('Fehler: Datei, Zeile und die vorhandenen Bauteile', err?.file === 'drawings/broken.py' && err.line === 3 && err.message.includes("'Brackett' does not exist")&& err.message.includes("'Bracket'"), JSON.stringify(err)?.slice(0, 160));@@ -137,6 +199,17 @@ print(json.dumps(dict(errors=len(aud.errors), types=types, layers=layers, detailconst b3 = soma(dir, 'drawing', 'build');check('Gelöschtes Blatt: PDF und DXF bleiben, die Ausgabe nennt sie, das Bild geht', b3.stdout.includes('Note: output/drawings/Checks.pdf belongs to no sheet anymore')&& fs.existsSync(path.join(dir, 'output', 'drawings', 'Checks.pdf')) && !fs.existsSync(path.join(dir, '.soma', 'drawings', 'Checks.png')), b3.stdout.slice(-300));+ // Ohne Fehler: alle Blätter in output/drawings.pdf, nach Datei geordnet. Ein Teilbau holt die übrigen Blätter aus der DXF+ fs.rmSync(path.join(dir, 'drawings', 'broken.py'));+ const b5 = soma(dir, 'drawing', 'build');+ const setPdf = path.join(dir, 'output', 'drawings.pdf');+ const pages = (buf) => (buf.toString('latin1').match(/\/Type\s*\/Page[^s]/g) ?? []).length;+ const set1 = fs.existsSync(setPdf) ? fs.readFileSync(setPdf) : Buffer.alloc(0);+ check('Gesamt-PDF output/drawings.pdf mit beiden Blättern', b5.status === 0 && b5.stdout.includes('All sheets in one file: output/drawings.pdf (2 sheet(s))')+ && pages(set1) === 2, `${pages(set1)} Seiten; ${b5.stdout.slice(-200)}`);+ soma(dir, 'drawing', 'build', 'drawings/skill.py');+ check('Gesamt-PDF bytegleich nach Teilbau (Blatt aus der DXF gleich dem frisch gebauten)', fs.existsSync(setPdf) && set1.equals(fs.readFileSync(setPdf)));+fs.appendFileSync(path.join(dir, 'model.py'), 'raise ValueError("kaputt")\n');const b4 = soma(dir, 'drawing', 'build');check('Modell baut nicht: Meldung mit Ort, keine Zeichnung', b4.status === 1 && b4.stderr.includes('The model does not build, so no drawing does either')