by adom
Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.
← Commit history
0.2.79 source (unreleased): generate_body marks the part (segment font on the body's top, raised or engraved)
5 files changed
+123−13
CHANGELOG.md+7@@ -1,5 +1,12 @@ # Changelog +## 0.2.79 (unreleased)++- `generate_body` marks the part: `marking` puts text on the body's top (a can's top for ecap) in a segment font+ (capitals, digits, - + / .), lines stacked, sized to fit the top. `markingStyle` raised stands 30 um proud, engraved+ is a 5 um layer flush on the top (the body is not cut). A light colour on the dark body; OCCT renders it legibly on a+ SOIC-8, a QFN-16 and a 6.3 mm can. Characters the font does not draw are listed under notApplied.+ ## 0.2.78 (2026-10-28) Six more of the EDA Bridge Standard's verbs (251 in all), all tried live on Altium Develop:
bridge-rs/src/body3d.rs+110−9@@ -9,7 +9,7 @@ type P3 = [f64; 3]; /// A solid as its faces, each a planar polygon listed counter-clockwise seen from outside. #[derive(Clone)]-pub struct Solid { pub faces: Vec<Vec<P3>>, pub lead: bool }+pub struct Solid { pub faces: Vec<Vec<P3>>, pub lead: bool, pub mark: bool } /// A prism: `outline` (counter-clockwise in its own u,v plane) swept from w0 to w1, placed by `map(u, v, w)`. fn prism(outline: &[(f64, f64)], w0: f64, w1: f64, lead: bool, map: impl Fn(f64, f64, f64) -> P3) -> Solid {@@ -21,7 +21,7 @@ fn prism(outline: &[(f64, f64)], w0: f64, w1: f64, lead: bool, map: impl Fn(f64, let (a, b) = (outline[i], outline[(i + 1) % n]); faces.push(vec![map(a.0, a.1, w0), map(b.0, b.1, w0), map(b.0, b.1, w1), map(a.0, a.1, w1)]); }- let mut s = Solid { faces, lead };+ let mut s = Solid { faces, lead, mark: false }; // a map that mirrors (an odd number of axis flips) turns every face inside out: put them right if signed_volume(&s) < 0.0 { for f in &mut s.faces { f.reverse(); } } s@@ -224,6 +224,7 @@ pub fn step(solids: &[Solid], name: &str) -> String { }; let body_style = style(&mut out, (0.15, 0.15, 0.16)); let lead_style = style(&mut out, (0.80, 0.80, 0.82));+ let mark_style = style(&mut out, (0.92, 0.92, 0.90)); for sol in solids { // shared vertices and edges, so the shell is closed let mut verts: Vec<(P3, usize)> = Vec::new();@@ -283,9 +284,9 @@ pub fn step(solids: &[Solid], name: &str) -> String { faces.push(add(&mut out, format!("ADVANCED_FACE('',(#{bound}),#{plane},.T.)"))); } let shell = add(&mut out, format!("CLOSED_SHELL('',({}))", faces.iter().map(|f| format!("#{f}")).collect::<Vec<_>>().join(",")));- let brep = add(&mut out, format!("MANIFOLD_SOLID_BREP('{}',#{shell})", if sol.lead { "lead" } else { "body" }));+ let brep = add(&mut out, format!("MANIFOLD_SOLID_BREP('{}',#{shell})", if sol.mark { "marking" } else if sol.lead { "lead" } else { "body" })); breps.push(brep);- styled.push(add(&mut out, format!("STYLED_ITEM('color',(#{}),#{brep})", if sol.lead { lead_style } else { body_style })));+ styled.push(add(&mut out, format!("STYLED_ITEM('color',(#{}),#{brep})", if sol.mark { mark_style } else if sol.lead { lead_style } else { body_style }))); } let rep = add(&mut out, format!("ADVANCED_BREP_SHAPE_REPRESENTATION('{name}',(#{ax},{}),#{ctx})", breps.iter().map(|b| format!("#{b}")).collect::<Vec<_>>().join(","))); add(&mut out, format!("SHAPE_DEFINITION_REPRESENTATION(#{pds},#{rep})"));@@ -293,6 +294,73 @@ pub fn step(solids: &[Solid], name: &str) -> String { format!("ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION(('altium-bridge generate_body'),'2;1');\nFILE_NAME('{name}.step','2026-01-01T00:00:00',(''),(''),'altium-bridge','altium-bridge','');\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN {{ 1 0 10303 214 1 1 1 1 }}'));\nENDSEC;\nDATA;\n{}\nENDSEC;\nEND-ISO-10303-21;\n", out.join("\n")) } +/// A segment font for markings: each character is strokes between the points of a 2 x 2 cell (x 0..1, y 0..2), as+/// a 16-segment display draws them plus two diagonals for V. Part markings use capitals, digits and a few signs.+fn glyph(c: char) -> Option<&'static [((f64, f64), (f64, f64))]> {+ const TL: (f64, f64) = (0.0, 2.0); const TM: (f64, f64) = (0.5, 2.0); const TR: (f64, f64) = (1.0, 2.0);+ const ML: (f64, f64) = (0.0, 1.0); const MM: (f64, f64) = (0.5, 1.0); const MR: (f64, f64) = (1.0, 1.0);+ const BL: (f64, f64) = (0.0, 0.0); const BM: (f64, f64) = (0.5, 0.0); const BR: (f64, f64) = (1.0, 0.0);+ const A: ((f64, f64), (f64, f64)) = (TL, TR); const B: ((f64, f64), (f64, f64)) = (TR, MR); const C: ((f64, f64), (f64, f64)) = (MR, BR);+ const D: ((f64, f64), (f64, f64)) = (BL, BR); const E: ((f64, f64), (f64, f64)) = (ML, BL); const F: ((f64, f64), (f64, f64)) = (TL, ML);+ const G1: ((f64, f64), (f64, f64)) = (ML, MM); const G2: ((f64, f64), (f64, f64)) = (MM, MR); const G: ((f64, f64), (f64, f64)) = (ML, MR);+ const VT: ((f64, f64), (f64, f64)) = (TM, MM); const VB: ((f64, f64), (f64, f64)) = (MM, BM); const V: ((f64, f64), (f64, f64)) = (TM, BM);+ const DTL: ((f64, f64), (f64, f64)) = (TL, MM); const DTR: ((f64, f64), (f64, f64)) = (TR, MM);+ const DBL: ((f64, f64), (f64, f64)) = (MM, BL); const DBR: ((f64, f64), (f64, f64)) = (MM, BR);+ const LB: ((f64, f64), (f64, f64)) = (ML, BM); const RB: ((f64, f64), (f64, f64)) = (MR, BM);+ const DOT: ((f64, f64), (f64, f64)) = ((0.4, 0.0), (0.6, 0.0));+ Some(match c.to_ascii_uppercase() {+ '0' => &[A, B, C, D, E, F, DTR, DBL], '1' => &[V], '2' => &[A, B, G, E, D], '3' => &[A, B, G2, C, D],+ '4' => &[F, G, B, C], '5' => &[A, F, G, C, D], '6' => &[A, F, E, D, C, G], '7' => &[A, B, C], '8' => &[A, B, C, D, E, F, G],+ '9' => &[A, B, C, D, F, G], 'A' => &[E, F, A, B, C, G], 'B' => &[A, B, C, D, V, G2], 'C' => &[A, F, E, D], 'D' => &[A, B, C, D, V],+ 'E' => &[A, F, E, D, G1], 'F' => &[A, F, E, G1], 'G' => &[A, F, E, D, C, G2], 'H' => &[F, E, B, C, G], 'I' => &[A, V, D],+ 'J' => &[B, C, D, E], 'K' => &[F, E, G1, DTR, DBR], 'L' => &[F, E, D], 'M' => &[E, F, B, C, DTL, DTR], 'N' => &[E, F, B, C, DTL, DBR],+ 'O' => &[A, B, C, D, E, F], 'P' => &[A, B, F, E, G], 'Q' => &[A, B, C, D, E, F, DBR], 'R' => &[A, B, F, E, G, DBR],+ 'S' => &[A, F, G, C, D], 'T' => &[A, V], 'U' => &[F, E, D, C, B], 'V' => &[F, B, LB, RB], 'W' => &[E, F, B, C, DBL, DBR],+ 'X' => &[DTL, DTR, DBL, DBR], 'Y' => &[DTL, DTR, VB], 'Z' => &[A, DTR, DBL, D], '-' => &[G], '+' => &[G, VT, VB],+ '/' => &[DTR, DBL], '.' => &[DOT], ' ' => &[],+ _ => return None,+ })+}++/// The marking as thin bars on the top face of `top` (the body's top), centred and sized to fit it, lines stacked.+/// Raised stands 30 um proud; engraved is a 5 um layer flush on the top (the body is not cut). Returns the solids and+/// the characters the font does not draw.+fn marking(text: &str, top: &Solid, engraved: bool) -> (Vec<Solid>, Vec<char>) {+ let b = bbox(std::slice::from_ref(top));+ let (w, d, z) = (b[3] - b[0], b[4] - b[1], b[5]);+ let (cx, cy) = ((b[0] + b[3]) / 2.0, (b[1] + b[4]) / 2.0);+ let lines: Vec<&str> = text.lines().filter(|l| !l.trim().is_empty()).collect();+ let mut skipped = Vec::new();+ if lines.is_empty() { return (Vec::new(), skipped); }+ // a character cell is 0.6 h wide with 0.25 h between characters; lines are 1.5 h apart+ let longest = lines.iter().map(|l| l.chars().count()).max().unwrap_or(1) as f64;+ let h = (0.85 * w / (longest * 0.85 - 0.25).max(0.6)).min(0.8 * d / (lines.len() as f64 * 1.5 - 0.5)).min(1.5);+ let stroke = (h * 0.12).max(0.03);+ let (z0, z1) = if engraved { (z, z + 0.005) } else { (z, z + 0.03) };+ let mut out = Vec::new();+ for (li, line) in lines.iter().enumerate() {+ let n = line.chars().count() as f64;+ let x0 = cx - (n * 0.85 - 0.25) * h / 2.0;+ let y0 = cy + (lines.len() as f64 * 1.5 - 0.5) * h / 2.0 - h - li as f64 * 1.5 * h;+ for (ci, ch) in line.chars().enumerate() {+ let Some(strokes) = glyph(ch) else { skipped.push(ch); continue };+ let ox = x0 + ci as f64 * 0.85 * h;+ for ((u0, v0), (u1, v1)) in strokes {+ // a stroke of the 0..1 x 0..2 cell, scaled to 0.6 h x h, as a bar `stroke` wide+ let (ax, ay, bx2, by) = (ox + u0 * 0.6 * h, y0 + v0 * 0.5 * h, ox + u1 * 0.6 * h, y0 + v1 * 0.5 * h);+ let len = (bx2 - ax).hypot(by - ay).max(1e-9);+ let (nx, ny) = (-(by - ay) / len * stroke / 2.0, (bx2 - ax) / len * stroke / 2.0);+ let (ex, ey) = ((bx2 - ax) / len * stroke / 2.0, (by - ay) / len * stroke / 2.0);+ let quad = vec![(ax - ex - nx, ay - ey - ny), (bx2 + ex - nx, by + ey - ny), (bx2 + ex + nx, by + ey + ny), (ax - ex + nx, ay - ey + ny)];+ let mut s = prism(&quad, z0, z1, false, |u, v, w| [u, v, w]);+ s.mark = true;+ out.push(s);+ }+ }+ }+ (out, skipped)+}+ fn bbox(solids: &[Solid]) -> [f64; 6] { solids.iter().flat_map(|s| s.faces.iter().flatten()).fold([f64::MAX, f64::MAX, f64::MAX, f64::MIN, f64::MIN, f64::MIN], |b, p| [b[0].min(p[0]), b[1].min(p[1]), b[2].min(p[2]), b[3].max(p[0]), b[4].max(p[1]), b[5].max(p[2])]) }@@ -311,16 +379,28 @@ pub fn generate_body(args: &Value) -> Value { if let Some(given) = args.get("dimensionsMm").and_then(|v| v.as_object()) { for (k, v) in given { if v.is_number() { dims.insert(k.clone(), v.clone()); } } }- let Some(solids) = package(name, &dims) else { return json!({"success": false, "errorCode": "unknown_family"}) };+ let Some(mut solids) = package(name, &dims) else { return json!({"success": false, "errorCode": "unknown_family"}) };+ // the marking sits on the body's top (an electrolytic can's top for ecap)+ let marking_text = args.get("marking").and_then(|v| v.as_str()).map(|t| t.replace("\\n", "\n")).filter(|t| !t.trim().is_empty());+ let engraved = args.get("markingStyle").and_then(|v| v.as_str()) == Some("engraved");+ let mut unmarked: Vec<char> = Vec::new();+ if let Some(t) = &marking_text {+ let top = solids[if *name == "ecap" { 1 } else { 0 }].clone();+ let (marks, skipped) = marking(t, &top, engraved);+ unmarked = skipped;+ solids.extend(marks);+ } let stem = std::path::Path::new(&path).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or("body".into()).replace('\'', ""); if let Some(p) = std::path::Path::new(&path).parent() { let _ = std::fs::create_dir_all(p); } if let Err(e) = std::fs::write(&path, step(&solids, &stem)) { return json!({"success": false, "errorCode": "write_failed", "error": format!("{path}: {e}")}); }- let b = bbox(&solids); let r3 = |v: f64| (v * 1000.0).round() / 1000.0;- let marking = args.get("marking").and_then(|v| v.as_str());+ // the box is the package's: a raised marking's 30 um is not part of the body's height+ let body: Vec<Solid> = solids.iter().filter(|s| !s.mark).cloned().collect();+ let b = bbox(&body); json!({"success": true, "stepPath": path, "family": name, "dimensionsMm": dims, "solids": solids.len(),- "bboxMm": {"x": r3(b[3] - b[0]), "y": r3(b[4] - b[1]), "z": r3(b[5] - b[2])}, "marking": Value::Null,- "notApplied": if marking.is_some() { json!(["marking: text geometry is not made yet; the body is plain"]) } else { json!([]) },+ "bboxMm": {"x": r3(b[3] - b[0]), "y": r3(b[4] - b[1]), "z": r3(b[5] - b[2])}, "marking": marking_text,+ "markingStyle": if marking_text.is_some() { json!(if engraved { "engraved (a 5 um layer flush on the top; the body is not cut)" } else { "raised 30 um" }) } else { Value::Null },+ "notApplied": if unmarked.is_empty() { json!([]) } else { json!([format!("marking characters the font does not draw: {}", unmarked.iter().collect::<String>())]) }, "_hint": "The body is in the package's own frame (IPC-7351 zero orientation, pin 1 top-left, seated on z = 0), ready for altium_add_body {libraryPath, footprintName, step}. Compare bboxMm with the datasheet's body size before attaching it."}) } @@ -366,6 +446,13 @@ mod tests { for (name, def) in families() { std::fs::write(format!("{dir}/{name}.step"), step(&package(name, def.as_object().unwrap()).unwrap(), name)).unwrap(); }+ for (name, text, idx) in [("soic", "NE555\nTI 2X4", 0), ("qfn", "STM32\nG031", 0), ("ecap", "100UF\n25V", 1)] {+ let def = families().into_iter().find(|f| f.0 == name).unwrap().1;+ let mut s = package(name, def.as_object().unwrap()).unwrap();+ let top = s[idx].clone();+ s.extend(marking(text, &top, false).0);+ std::fs::write(format!("{dir}/{name}-marked.step"), step(&s, name)).unwrap();+ } } #[test]@@ -380,4 +467,18 @@ mod tests { let max = *ids.iter().max().unwrap(); for cap in t.split('#').skip(1) { let n: String = cap.chars().take_while(|c| c.is_ascii_digit()).collect(); if let Ok(n) = n.parse::<usize>() { assert!(n <= max); } } }++ #[test]+ fn a_marking_sits_on_the_body_top_and_fits_it() {+ let dims = families().into_iter().find(|f| f.0 == "soic").unwrap().1;+ let s = package("soic", dims.as_object().unwrap()).unwrap();+ let (m, skipped) = marking("NE555\nTI 2X", &s[0], false);+ assert!(skipped.is_empty());+ assert!(!m.is_empty());+ let (body, mb) = (bbox(&s[..1]), bbox(&m));+ assert!((mb[2] - 1.75).abs() < 1e-9 && (mb[5] - 1.78).abs() < 1e-9, "{mb:?}");+ assert!(mb[0] > body[0] && mb[3] < body[3] && mb[1] > body[1] && mb[4] < body[4], "inside the top: {mb:?} {body:?}");+ for x in &m { assert!(closed(x) && signed_volume(x) > 0.0); }+ assert_eq!(marking("A~B", &s[0], true).1, vec!['~']);+ } }
bridge-rs/src/verbs.rs+2−2@@ -765,9 +765,9 @@ fn describe() -> Value { json!({"file": "path"}), 600, "Name the part fields with bomFields, or the BOM inside the file carries no part numbers.", &["export_manufacturing", "run_drc"], &["Run run_drc first: the file carries the board's errors with it.", "Altium writes it with its manufacturing template's settings: units, compression and version options are reported under optionsNotApplied.", "The board must be a document of a .PrjPcb in its folder."], json!({"filePath": "C:/proj/Board.PcbDoc", "bomFields": {"mpn": "MPN"}})), verb_doc("generate_body", "Make a part's 3D body from its package family and its datasheet dimensions (chip, SOIC, QFN, QFP, BGA, SOT-23, DFN, MELF, electrolytic can, crystal, pin header), to IPC-7351 proportions, and write it as a STEP file.",- json!({"family": "chip | soic | qfn | qfp | bga | sot23 | dfn | melf | ecap | crystal | header (required; an unknown one is answered with the families the bridge supports)", "dimensionsMm": "{letter: mm}: the package drawing's JEDEC letters (A height, A1 standoff, D body length, E lead span, E1 body width, D1 body length of a QFP, b lead width, e pitch, L lead length, c lead thickness, D2/E2 exposed pad) plus pins (rows, cols for a BGA); a missing one takes the family's default", "marking": "text on the top face (not made yet: reported under notApplied)", "markingStyle": "raised | engraved (default raised)", "outputPath": "the .step file to write (required)"}),+ json!({"family": "chip | soic | qfn | qfp | bga | sot23 | dfn | melf | ecap | crystal | header (required; an unknown one is answered with the families the bridge supports)", "dimensionsMm": "{letter: mm}: the package drawing's JEDEC letters (A height, A1 standoff, D body length, E lead span, E1 body width, D1 body length of a QFP, b lead width, e pitch, L lead length, c lead thickness, D2/E2 exposed pad) plus pins (rows, cols for a BGA); a missing one takes the family's default", "marking": "text on the top face (an MPN or a value code); a newline starts a second line. Capitals, digits and - + / . in a segment font, sized to fit the top", "markingStyle": "raised (30 um proud, the default) | engraved (a 5 um layer flush on the top: the body is not cut)", "outputPath": "the .step file to write (required)"}), json!({"stepPath": "path", "family": "string", "dimensionsMm": "{letter: mm}: every dimension used, defaults included", "bboxMm": "{x, y, z}", "solids": "int", "marking": "string | null", "families": "[string] (when family is unknown)"}), 60,- "The body is in the package's own frame (IPC-7351 zero orientation, pin 1 top-left, seated on z = 0), ready for add_body. Compare bboxMm with the datasheet's body size before attaching it.", &["add_body", "bodies", "export_step"], &["A wrong dimension gives a plausible but wrong body: nothing checks it against a datasheet.", "Written by the bridge, no CAD tool needed: plain prisms (round cans and balls are many-sided), a dark body and bright leads.", "A marking is not made yet: the body is plain and notApplied says so."], json!({"family": "soic", "dimensionsMm": {"pins": 8, "D": 4.9, "E1": 3.9, "E": 6.0, "A": 1.75, "e": 1.27}, "outputPath": "C:/lib/SOIC8.step"})),+ "The body is in the package's own frame (IPC-7351 zero orientation, pin 1 top-left, seated on z = 0), ready for add_body. Compare bboxMm with the datasheet's body size before attaching it.", &["add_body", "bodies", "export_step"], &["A wrong dimension gives a plausible but wrong body: nothing checks it against a datasheet.", "Written by the bridge, no CAD tool needed: plain prisms (round cans and balls are many-sided), a dark body and bright leads.", "A marking is real geometry in a segment font: very small text on a small package is unreadable, which is not an error; characters the font does not draw are listed under notApplied."], json!({"family": "soic", "dimensionsMm": {"pins": 8, "D": 4.9, "E1": 3.9, "E": 6.0, "A": 1.75, "e": 1.27}, "outputPath": "C:/lib/SOIC8.step"})), verb_doc("edit_footprint", "Edit a library footprint in place: change, delete, add or renumber pads; add, replace or delete graphics on a layer; set its description; replace, add or delete 3D models. Everything not edited stays as it was.", json!({"libraryPath": "path to the footprint library (required)", "name": "the footprint's name (required)", "pads": "[{number, set?: {sizeMm, at, shape, drillMm, layers, rotation, type, newNumber}, delete?: true}]", "addPads": "[pad]: {number, at, sizeMm, shape, drillMm, layers, rotation, type}", "renumber": "{map: {\"1\": \"A1\"}} | {sequential: true, start?: 1}", "graphics": "[{layer, mode: append|replace|delete, widthMm?, shapes: [{type: line {start, end} | arc {center, radius, startAngle, endAngle} | rect {start, end} | circle {center, radius} | poly {points}}]}]", "metadata": "{description?, tags?, attributes?}", "models": "{mode: replace|append|delete, list: [{path, offset, scale, rotate}]}", "dryRun": "bool, default false: answer the plan and change nothing"}), json!({"changes": "[string]: what was done, in order (ok:... or err:...)", "notApplied": "[string]", "footprint": "{pads, graphics, courtyardMm} read back"}), 300,
dev-skills/altium-bridge-test/run_verb_tests.py+2−2@@ -429,8 +429,8 @@ def matrix(w): check=lambda d: len(d.get("files") or []) == 2 and not d.get("unknownLayers")) M["export_gencad"] = dict(phase=4, timeout=300, **ok(filePath=LB, outputDir=D + "/gencad", uniquePins=True), check=lambda d: str(d.get("file", "")).endswith(".cad") and (d.get("counts") or {}).get("components", 0) > 0)- M["generate_body"] = dict(phase=4, **ok(family="qfn", outputPath=D + "/bodies/QFN16.step"),- check=lambda d: abs(((d.get("bboxMm") or {}).get("x") or 0) - 4.0) < 0.01)+ M["generate_body"] = dict(phase=4, **ok(family="qfn", outputPath=D + "/bodies/QFN16.step", marking="STM32\nG031"),+ check=lambda d: abs(((d.get("bboxMm") or {}).get("x") or 0) - 4.0) < 0.01 and d.get("marking") and not d.get("notApplied")) M["export_step"] = dict(phase=4, timeout=300, **anyo("STEP of the battery board", filePath=PD, output=D + "/battery.step")) M["export_bom"] = dict(phase=4, **anyo("missing OutJob: named refusal (the demo OutJob opens its .xlsx on screen)", outjobPath=D + "/missing.OutJob")) M["export_gerber"] = dict(phase=4, **anyo("missing OutJob: named refusal", outjobPath=D + "/missing.OutJob"))
skills/altium-libraries/SKILL.md+2@@ -217,4 +217,6 @@ altium_footprint_from_land_pattern '{"libraryPath":"C:\\lib\\Parts.PcbLib","name sot23, qfp, qfn, dfn, bga, melf, ecap, crystal, header) and the datasheet's JEDEC letters; missing letters take the family's defaults, and `dimensionsMm` in the reply lists every one used. Compare `bboxMm` with the datasheet, then attach it with altium_add_body (or `edit_footprint {models: {mode: "replace", list: [{path}]}}`).+ `marking: "NE555\nTI"` prints the part number on the top (capitals, digits, `- + / .`; raised 30 um, or+ `markingStyle: "engraved"` for a flush etch).