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.82 (unreleased): simulate sweeps a part's value or a parameter, and the temperature (Altium's sweep list and _UserValue twins written); checked against ngspice
4 files changed
+80−12
CHANGELOG.md+5@@ -16,6 +16,11 @@ netlist's elements are compared with the sheet's parts: none simulated refuses `no_model` with the parts named (6 s on the battery's lane sheet), and a partly modelled sheet runs and lists the rest in `notSimulated`. A run that has not answered in 95 s says so instead of timing out.+- **`altium_simulate` sweeps**: `sweep {parameter, start, stop, step, scale?}` runs the analysis again for each value of a+ part's value or a sheet parameter, and `temperatures {start, stop, step}` at each temperature; every run is its own+ signal with its `step` (`R4 = 300`). Altium's run reads its sweep list (`ParamSweep_Custom...0`), not the keys its+ dialog shows, and a number's `_UserValue` twin before the number: both are written. Checked against ngspice on the+ example amplifier: 3.2735 dB at R4 = 300 and 12.8159 dB at 900 (10 MHz), the same to the last digit. - **`altium_simulate` runs the analysis asked for on every sheet.** A sheet with no simulation settings of its own ran on what Altium stored for it (sheet 1 of Altium's example ran its old AC sweep for an `op`): it now gets its own settings, keyed by its id in the project (given one when it has none, as a bridge-made project's sheets do), and a new
bridge-rs/src/sim.rs+66−10@@ -91,7 +91,7 @@ fn num_text(v: f64) -> String { /// The config keys for an analysis (the standard's `analysis`), or the refusal. Every other analysis is switched off, /// sweeps and Monte Carlo too, so the run is exactly the one asked for. Pure.-pub fn analysis_keys(a: &Value, probes: &[String]) -> Result<(String, Vec<(String, String)>, Vec<String>), Value> {+pub fn analysis_keys(a: &Value, probes: &[String], sweep: Option<&Value>, temps: Option<&Value>) -> Result<(String, Vec<(String, String)>, Vec<String>), Value> { let bad = |m: &str| json!({"success": false, "errorCode": "bad_args", "error": m}); let t = a["type"].as_str().unwrap_or("").to_ascii_lowercase(); let n = |k: &str| a.get(k).and_then(|v| v.as_f64());@@ -100,7 +100,9 @@ pub fn analysis_keys(a: &Value, probes: &[String]) -> Result<(String, Vec<(Strin let mut set = |k: &str, v: String| { kv.retain(|(a, _)| a != k); kv.push((k.into(), v.clone()));- if !k.ends_with("_Analysis") && !k.contains("Sweep") && !k.ends_with("Source") { kv.push((format!("{k}_UserValue"), v)); }+ // a number has a _UserValue twin, which Altium reads first when it is set (a TempSweep_Step without it was ignored:+ // the old 10 degree step ran, 2026-10-29); words (sources, parameters, sweep types, flags) have none+ if v.parse::<f64>().is_ok() { kv.retain(|(a, _)| a != &format!("{k}_UserValue")); kv.push((format!("{k}_UserValue"), v)); } }; match t.as_str() { "op" => set("OP_Analysis", "True".into()),@@ -132,12 +134,50 @@ pub fn analysis_keys(a: &Value, probes: &[String]) -> Result<(String, Vec<(Strin "_hint": "Give the analysis in the structured form (op, dc, ac, tran)."})), _ => return Err(bad("analysis.type is op, dc, ac, tran or raw")), }+ let mut sweep_drop: Vec<String> = Vec::new();+ // a parameter sweep: the analysis again for each value of a part's value (C6) or a sheet parameter, every step its+ // own signal (v(out)_p1 ...). Step is the increment for lin, the points per decade or octave for dec and oct, as+ // Altium's own ParamSweep keys take it+ if let Some(sw) = sweep.filter(|v| !v.is_null()) {+ let f = |k: &str| sw.get(k).and_then(|v| v.as_f64());+ let (Some(par), Some(st), Some(en), Some(step)) = (sw["parameter"].as_str(), f("start"), f("stop"), f("step")) else {+ return Err(bad("sweep is {parameter: \"C6\" (a part) or a sheet parameter, start, stop, step, scale?: lin|dec|oct}"));+ };+ let scale = sw["scale"].as_str().unwrap_or("lin").to_ascii_uppercase();+ if !["LIN", "DEC", "OCT"].contains(&scale.as_str()) { return Err(bad("sweep.scale is lin, dec or oct")); }+ if step <= 0.0 { return Err(bad("sweep.step is above 0")); }+ let n = if scale == "LIN" { ((en - st) / step).abs().floor() + 1.0 } else {+ if st <= 0.0 || en <= 0.0 { return Err(bad("a dec or oct sweep runs over positive values")); }+ let per = (en / st).abs().ln() / if scale == "DEC" { 10f64.ln() } else { 2f64.ln() };+ (per * step).round() + 1.0+ };+ if n > 50.0 { return Err(bad(&format!("the sweep makes {n} runs: 50 at most"))); }+ set("ParamSweep_Analysis", "True".into());+ set("ParamSweep_Parameter1", par.into());+ set("ParamSweep_Type1", scale.clone());+ set("ParamSweep_Start1", num_text(st)); set("ParamSweep_Stop1", num_text(en)); set("ParamSweep_Step1", num_text(step));+ set("ParamSweep_SecondaryEnabled", "False".into());+ // the run reads Altium's sweep list (ParamSweep_Custom...0), not the ...1 keys its dialog shows: R4 asked for there+ // ran the stored C6 sweep (2026-10-29). Ours is the list's only entry+ set("ParamSweep_CustomEnabled0", "True".into());+ set("ParamSweep_CustomParameter0", par.into());+ set("ParamSweep_CustomType0", if scale == "LIN" { "LIN".into() } else { scale.clone() });+ set("ParamSweep_CustomStart0", num_text(st)); set("ParamSweep_CustomStop0", num_text(en)); set("ParamSweep_CustomStep0", num_text(step));+ sweep_drop.push("ParamSweep_Custom".into());+ }+ if let Some(tp) = temps.filter(|v| !v.is_null()) {+ let f = |k: &str| tp.get(k).and_then(|v| v.as_f64());+ let (Some(st), Some(en), Some(step)) = (f("start"), f("stop"), f("step")) else { return Err(bad("temperatures is {start, stop, step} in degrees C")) };+ if step <= 0.0 || ((en - st) / step).abs() > 49.0 { return Err(bad("temperatures: a step above 0, and 50 runs at most")); }+ set("TempSweep_Analysis", "True".into());+ set("TempSweep_Start", num_text(st)); set("TempSweep_Stop", num_text(en)); set("TempSweep_Step", num_text(step));+ } // a run keeps only the signals its analysis lists (AC_Variable0=dB(v(out)) kept v(out) alone): the probes become // that list, in place of the sheet's own. An operating point keeps every node and current anyway- let mut drop = Vec::new();+ let mut drop = sweep_drop; let pre = match t.as_str() { "ac" => "AC", "tran" => "TRAN", "dc" => "DC", _ => "" }; if !pre.is_empty() && !probes.is_empty() {- drop = vec![format!("{pre}_Variable"), format!("{pre}_XVariable")];+ drop.extend([format!("{pre}_Variable"), format!("{pre}_XVariable")]); for (i, p) in probes.iter().enumerate() { for (k, v) in [("VariableEnabled", "True".to_string()), ("XVariable", String::new()), ("Variable", p.clone()), ("VariableName", String::new()), ("VariableUnits", String::new()), ("VariablePlot", "0".into()), ("VariableAxis", "0".into()), ("VariableColor", "8421504".into())] {@@ -318,8 +358,8 @@ fn newest(dir: &Path, ext: &str, since: std::time::SystemTime) -> Option<PathBuf /// Write the analysis into the project's .simcfg with the project closed (an edit made while it is open is not read: /// Altium keeps its own copy), then reopen it. Refuses over unsaved documents of that project.-fn configure(sheet: &Path, prj: &Path, analysis: &Value, probes: &[String]) -> Result<String, Value> {- let (kind, kv, drop) = analysis_keys(analysis, probes)?;+fn configure(sheet: &Path, prj: &Path, analysis: &Value, probes: &[String], sweep: Option<&Value>, temps: Option<&Value>) -> Result<String, Value> {+ let (kind, kv, drop) = analysis_keys(analysis, probes, sweep, temps)?; let dir = prj.parent().unwrap_or(Path::new(".")); let c = crate::project::close_all_documents(&json!({"under": dir.to_string_lossy()})); let mut kept = c["keptOpen"].as_array().cloned().unwrap_or_default();@@ -439,7 +479,10 @@ pub fn simulate(args: &Value) -> Value { if let Some(g) = crate::support::need_licensed() { return g; } let (sheet, prj) = match sheet_and_project(args) { Ok(x) => x, Err(e) => return e }; let probes: Vec<String> = args.get("probes").and_then(|v| v.as_array()).map(|a| a.iter().filter_map(probe_name).collect()).unwrap_or_default();- let kind = match args.get("analysis").filter(|a| !a.is_null()) { Some(a) => match configure(&sheet, &prj, a, &probes) { Ok(k) => Some(k), Err(e) => return e }, None => None };+ if args.get("analysis").map(|a| a.is_null()).unwrap_or(true) && (args.get("sweep").is_some() || args.get("temperatures").is_some()) {+ return json!({"success": false, "errorCode": "bad_args", "error": "a sweep runs an analysis again for each value: give the analysis too"});+ }+ let kind = match args.get("analysis").filter(|a| !a.is_null()) { Some(a) => match configure(&sheet, &prj, a, &probes, args.get("sweep"), args.get("temperatures")) { Ok(k) => Some(k), Err(e) => return e }, None => None }; let (sdf, nsx, _) = match run(&sheet, &prj) { Ok(x) => x, Err(e) => return e }; let missing_models = nsx.as_ref().map(|n| not_simulated(&sheet, n)).unwrap_or_default(); let Some(sdf) = sdf else {@@ -544,14 +587,14 @@ mod tests { #[test] fn analyses_become_altiums_settings() {- let (k, kv, drop) = analysis_keys(&json!({"type": "ac", "sweep": "dec", "points": 20, "start": 10, "stop": 1e6}), &["v(out)".into(), "i(r4)".into()]).unwrap();+ let (k, kv, drop) = analysis_keys(&json!({"type": "ac", "sweep": "dec", "points": 20, "start": 10, "stop": 1e6}), &["v(out)".into(), "i(r4)".into()], None, None).unwrap(); assert_eq!(k, "ac"); let cfg = set_config("OP_Analysis=True|AC_TestPoints=1000|AC_Variable0=dB(v(in))|AC_VariableEnabled0=True|AC_XVariable0=|Other=x", &kv, &drop); assert!(cfg.contains("AC_Variable0=v(out)") && cfg.contains("AC_Variable1=i(r4)") && !cfg.contains("v(in)"), "the probes replace the sheet's own signals: {cfg}"); assert!(cfg.contains("OP_Analysis=False") && cfg.contains("AC_Analysis=True") && cfg.contains("AC_TestPoints=20") && cfg.contains("AC_StopFrequency=1000000") && cfg.contains("Other=x"), "{cfg}"); assert!(cfg.contains("ParamSweep_Analysis=False"), "sweeps are switched off");- assert_eq!(analysis_keys(&json!({"type": "raw", "text": ".op"}), &[]).unwrap_err()["errorCode"], "not_supported");- assert_eq!(analysis_keys(&json!({"type": "tran", "stop": 1}), &[]).unwrap_err()["errorCode"], "bad_args");+ assert_eq!(analysis_keys(&json!({"type": "raw", "text": ".op"}), &[], None, None).unwrap_err()["errorCode"], "not_supported");+ assert_eq!(analysis_keys(&json!({"type": "tran", "stop": 1}), &[], None, None).unwrap_err()["errorCode"], "bad_args"); let xml = "<P><Settings></Settings>\n <Config>OP_Analysis=True</Config>\n <Documents><DocumentConfig><Name>a.SchDoc</Name><Config>AC_TestPoints=5</Config></DocumentConfig>\n<DocumentConfig><Name>b.SchDoc</Name><Config>AC_TestPoints=7</Config></DocumentConfig></Documents></P>"; let out = write_simcfg(xml, "b.SchDoc", None, &kv, &drop); assert!(out.contains("<Name>a.SchDoc</Name><Config>AC_TestPoints=5</Config>"), "another sheet's settings stay: {out}");@@ -598,4 +641,17 @@ mod tests { assert!(t.contains("DocumentPath=lane.SchDoc\r\nDocumentUniqueId=NEWIDXYZ\r\n"), "{t:?}"); assert_eq!(sheet_unique_id(prj, "lane.PcbDoc", "X").1, "QQQQQQQQ"); }+ #[test]+ fn sweeps_become_altiums_param_and_temperature_keys() {+ let ac = json!({"type": "ac", "sweep": "dec", "points": 10, "start": 10, "stop": 1e8});+ let (_, kv, drop) = analysis_keys(&ac, &[], Some(&json!({"parameter": "C6", "start": 1e-10, "stop": 1e-4, "step": 1, "scale": "dec"})), Some(&json!({"start": -10, "stop": 60, "step": 35}))).unwrap();+ let cfg = set_config("ParamSweep_Analysis=False|ParamSweep_CustomParameter1=R9|ParamSweep_CustomEnabled1=True", &kv, &drop);+ assert!(cfg.contains("ParamSweep_CustomParameter0=C6") && cfg.contains("ParamSweep_CustomStart0_UserValue=0.0000000001") && !cfg.contains("R9"), "the sweep list holds ours alone: {cfg}");+ assert!(cfg.contains("ParamSweep_Analysis=True") && cfg.contains("ParamSweep_Parameter1=C6") && cfg.contains("ParamSweep_Type1=DEC") && cfg.contains("ParamSweep_Start1=0.0000000001"), "{cfg}");+ assert!(cfg.contains("TempSweep_Analysis=True") && cfg.contains("TempSweep_Stop=60") && cfg.contains("TempSweep_Step_UserValue=35"), "{cfg}");+ assert!(cfg.contains("ParamSweep_Step1_UserValue=1") && !cfg.contains("ParamSweep_Parameter1_UserValue"), "numbers get their twin, words do not: {cfg}");+ assert_eq!(analysis_keys(&ac, &[], Some(&json!({"parameter": "R1", "start": 1, "stop": 1000, "step": 1})), None).unwrap_err()["errorCode"], "bad_args", "1000 runs is too many");+ let (_, plain, _) = analysis_keys(&ac, &[], None, None).unwrap();+ assert!(set_config("ParamSweep_Analysis=True", &plain, &[]).contains("ParamSweep_Analysis=False"), "no sweep switches an old one off");+ } }
bridge-rs/src/verbs.rs+2−2@@ -433,8 +433,8 @@ fn describe() -> Value { "No rates are built in, so none can go stale: read the fab's current prices from its page, pass them as prices with the date read, and the reply prices the quantities from them. altium_fab_check compares the same numbers with a fab's limits. altium_jlcpcb_order makes the order files.", &["fab_check", "jlcpcb_order", "layer_stack", "board_report"], &["A rough estimate only: get a real quote before ordering."], json!({"quantities": [5, 30]})), verb_doc("simulate", "Run a circuit simulation of a schematic sheet in Altium's mixed-signal simulator (Advanced Sim) and return the signals as data: an operating point, a DC sweep, an AC sweep or a transient, as the standard's simulate gives them.",- json!({"schematic": "the .SchDoc to simulate (filePath works too); it must belong to a .PrjPcb beside it", "analysis": "{type: op} | {type: dc, source: V1, start, stop, step} | {type: ac, sweep: dec|oct|lin, points, start, stop} (Hz) | {type: tran, step, stop, start?} (s); omitted: the analyses the design carries. {type: raw} is refused (not_supported): Altium netlists the schematic itself", "probes": "[{net: OUT} | {current: R3} | {signal: \"v(out)\"}]; with an analysis they become the signals the run keeps; omitted: the signals the design's own simulation setup keeps (an operating point keeps every node and current)", "points": "int, default 200: a ceiling per signal (the first, last and extreme points are kept)"}),- json!({"signals": "[{signal, analysis, x, y, xUnit, yUnit, phase? (AC, degrees unwrapped), step? (a sweep's step)}]", "missing": "[probes the run did not have]", "available": "[every signal of the run]", "engine": "string", "results": "path of Altium's .sdf", "netlist": "path of the .nsx it ran"}), 900,+ json!({"schematic": "the .SchDoc to simulate (filePath works too); it must belong to a .PrjPcb beside it", "analysis": "{type: op} | {type: dc, source: V1, start, stop, step} | {type: ac, sweep: dec|oct|lin, points, start, stop} (Hz) | {type: tran, step, stop, start?} (s); omitted: the analyses the design carries. {type: raw} is refused (not_supported): Altium netlists the schematic itself", "probes": "[{net: OUT} | {current: R3} | {signal: \"v(out)\"}]; with an analysis they become the signals the run keeps; omitted: the signals the design's own simulation setup keeps (an operating point keeps every node and current)", "sweep": "{parameter: C6 (a part's value) or a sheet parameter, start, stop, step, scale?: lin|dec|oct}: the analysis again for each value (step is the increment for lin, points per decade or octave for dec and oct); 50 runs at most", "temperatures": "{start, stop, step} in degrees C: the analysis again at each temperature", "points": "int, default 200: a ceiling per signal (the first, last and extreme points are kept)"}),+ json!({"signals": "[{signal, analysis, x, y, xUnit, yUnit, phase? (AC, degrees unwrapped), step? (a sweep step, e.g. C6 = 1e-10)}]: in a sweep each run is its own signal (v(out)_p1, v(out)_p2 ...)", "notSimulated": "[parts the netlister left out: no simulation model]", "missing": "[probes the run did not have]", "available": "[every signal of the run]", "engine": "string", "results": "path of Altium's .sdf", "netlist": "path of the .nsx it ran"}), 900, "With analysis, the project's documents are closed, the analysis is written into its .simcfg (for this sheet and the project) and the project is reopened: Altium reads the file only on opening. Unsaved documents of that project refuse it (unsaved_changes). AC y is in dB with phase beside it. Every part needs a simulation model (Altium's generic R, C, L, sources and the models of its simulation libraries).", &["export_spice", "compile", "open_project"], &["A part with no simulation model stops the netlister: simulation_failed, and Altium's Messages name it.", "The run also opens Altium's results document; it is saved beside the project (Simulation folder) and closed."], json!({"schematic": "C:/proj/Filter.SchDoc", "analysis": {"type": "ac", "sweep": "dec", "points": 20, "start": 10, "stop": 1e6}, "probes": [{"net": "OUT"}]})), verb_doc("export_spice", "The schematic's SPICE netlist from Altium's mixed-signal simulator (the .nsx its Mixed Sim output writes): elements, analyses, models.",
skills/altium-schematic-edit/SKILL.md+7@@ -221,6 +221,13 @@ altium_export_spice '{"schematic":"C:/proj/Amp.SchDoc","outputPath":"C:/proj/Amp you get what the design's own setup keeps. - Checked against ngspice on Altium's "Simulation Quick Start" amplifier: the operating point and all 71 AC points agree to 0.0001 dB.+- **Sweeps** run the analysis again per value, each run its own signal (`v(out)_p1`, `v(out)_p2` ... with `step`:+ `R4 = 300`): `"sweep": {"parameter": "R4", "start": 300, "stop": 900, "step": 300}` (a part's value or a sheet+ parameter; `scale: dec|oct` takes step as points per decade or octave), and `"temperatures": {"start": -10, "stop":+ 60, "step": 35}`. 50 runs at most. Checked against ngspice: the amplifier's gain at 10 MHz is 3.2735 dB at R4 = 300+ and 12.8159 dB at 900, exactly.+- A part with no simulation model is dropped by Altium's netlister without a word: none modelled refuses `no_model`+ (the parts named), some modelled runs and lists the rest in `notSimulated`. - `export_spice` returns the `.nsx` netlist (elements, analyses, includes). Altium writes it only as part of a run, so the sheet is simulated too. - Refusals: `unsaved_changes` (save the project's documents first: it is closed to write the analysis),