Open In progress bug report

sch_place_part / create_part_project drop SIM models; how to add a SPICE model that reaches the IntLib

MartyPM · ·marked in progress by kcknox

altium-bridge 0.2.113 · Altium Designer Develop 26.x (licensed) · Windows 11 (Hydrogen local workspace)

1. altium_sch_place_part and altium_create_part_project drop the symbol's simulation model

What I did: a SchLib symbol (a switching diode) carries three implementations: a PCBLIB footprint, a SIM model (added through Altium's Sim Model dialog from a manufacturer .mdl), and the STRESS model Altium adds with it. I placed it on a sheet two ways:

  • altium_create_part_project {part, libraryPath, outputDir} (the part lands on the sheet as U1)
  • altium_sch_place_part {sheet, library, symbol, designator:"D1", x, y}

Expected: the placed part carries every implementation of the library symbol, as a placement from the Components panel does.

What happened: both placed parts carry only the footprint. A DelphiScript walk of the sheet's implementations gives, for each:

comp U1 lib=<symbol> src=<path>.SchLib
  impl PCBLIB <footprint> cur=True map=(2:2),(1:1)
comp D1 lib=<symbol> src=<path>.SchLib
  impl PCBLIB <footprint> cur=True map=(2:2),(1:1)

So altium_simulate {analysis:{type:"op"}} refuses with no_model: "no part of the sheet has a simulation model: the netlist holds no elements" (parts: ["U1"]), and altium_export_spice writes a netlist with no D element. A library with a correct SIM model cannot be tested through the bridge.

altium_sch_update_from_library {sheet, designators} answered "unchanged" (same pins), so it doesn't restore the model either.

Ask: copy all implementations (SIM, STRESS, PCB3D, etc.) when placing, or place through Altium's own library placement. At least, say in the reply which model types were not carried over, so a caller doesn't read a missing model as a library fault.

2. Adding a SPICE model to a SchLib symbol: what works and what doesn't

There's no verb for this (altium_add_models and altium_set_models take footprints only). The skill could document it, or a verb (altium_add_sim_model {libraryPath, symbolName, mdlPath, pinMap}) could do it. What I found:

A scripted SIM implementation is not enough. This saves cleanly:

AddSchImplementation with ModelType SIM, Description Diode, ModelName, AddDataFileLink(name, file.mdl, 'MDL'), MapAsString, plus parameters on the implementation copied from Altium's own example diode (Spice Prefix=D, Kind=General, SubKind=Diode, the Netlist template, Area Factor and the rest).

But the IntLib compiler does not pack it: no MDL/ stream, and LibCrossRef.Txt lists only the PCBLIB model. This held whether the datafile link was relative, absolute, or absent (UseComponentLibrary). Setting Impl.UseComponentLibrary := False from a script did not stick.

The Sim Model dialog writes a different form, and that one works. The user added the model through the dialog and saved. Its records are:

  • RECORD=45 ... Description=Model Description|ModelName=<name>|ModelType=SIM|DatafileCount=1|ModelDatafile0=<full path>.mdl|ModelDatafileEntity0=<name>|ModelDatafileKind0=mdl|IsCurrent=T (lower-case mdl, no UseComponentLibrary or DatalinksLocked).
  • Map records (RECORD=47) as usual.
  • Parameters on the implementation:
    • Kind, SubKind, Spice Prefix, Excluded Parts, Syntax, SimulationCacheLocation (ReadOnlyState=3), Source=Local.
    • A longer Netlist template (with ?DTEMP, ?L, ?M, ?PJ, ?SENS_AREA, ?T_REL_LOCAL, ?W clauses, stored as %UTF8%Text).
    • Every .MODEL parameter copied in as its own parameter (IS, RS, BV, IBV, CJO, M/MJSW, N, TT, ...), with SPICE defaults for the ones the file omits.
  • A separate ModelType=STRESS implementation (ModelName Diode) with a PortMap and empty derating parameters (IF, IFD, IFS, IRMX, PDM, VR, VD, TJ, RJC, RCA).

After that, the LibPkg compiles to an IntLib with MDL/0.mdl and a SIM entry in LibCrossRef.Txt.

Also worth documenting:

  • Vendor SPICE files often have an uncommented title line between the comment header and .MODEL; strip to a clean .mdl before linking.
  • Add the .mdl to the LibPkg as a document.
  • SPICE diode nodes are anode, cathode. With cathode = pin 1, map symbol 1 to model 2 and symbol 2 to model 1.
  • A simulation run opens its own window with a second Altium taskbar icon, which a user can mistake for a second Altium instance.

7 Replies

MartyPM ·

altium-bridge 0.2.113 · Altium Designer Develop 26.x · Windows 11

Follow-up after more digging. The user confirmed that the placement method was the problem, not the library.

1. sch_place_part and create_part_project rebuild the part instead of placing it

The library symbol carries 4 implementations (PCBLIB footprint, SIM, STRESS) and 18 component-level parameters. Parsing the saved .SchDoc after each verb shows a component that was built, not placed:

  • The pins, polygon and polyline are copied in as the component's children.
  • All 94 parameters are flattened onto the component as plain parameters. That's the 18 real ones plus every SIM implementation parameter (Kind, SubKind, Spice Prefix, Netlist, Syntax, Source, IS, RS, BV, CJO, N, TT, ...) and the STRESS parameters (PortMap, IF, VR, TJ, ...). Some show on the sheet: the SIM Netlist template appears as a long visible text line next to the part.
  • The SIM and STRESS implementations are dropped. Only the PCBLIB one survives.
  • The sch_place_part copy has PartCount=1 (the library symbol has PartCount=2, i.e. one part) and no DesignItemId.

To a user, the result looks like an exploded set of primitives rather than a library part.

Placement that works: SchServer.LoadComponentFromLibrary('<libRef>', '<path>.SchLib'), then Doc.AddSchObject(comp) and comp.MoveToXY(...). On the same sheet, that copy has PartCount=2, a DesignItemId, exactly its 18 parameters, and all three implementations.

With the rebuilt copy deleted and a source wired to the correctly placed diode, Altium simulates it. The .nsx holds DD9 0 K 1N4148WS and the manufacturer .MODEL line. (IntegratedLibraryManager.PlaceLibraryComponent(...) from a script raised a script error here.)

Ask: place through Altium's own library placement (as above, or the Components panel route altium_workspace_place already uses) so the component keeps its implementations, parameters and identity. If a rebuild is ever needed, don't promote implementation parameters to component parameters, and say in the reply which implementations were dropped.

2. altium_set_models removes SIM and STRESS models too

The table describes it as "replace every footprint model on a symbol with ONE PCBLIB model". On a symbol with PCBLIB + SIM + STRESS implementations, altium_set_models {libraryPath, symbolName, footprint} replied removed: 3, and the saved SchLib held only the new PCBLIB implementation. The user's hand-made simulation model was lost. (I restored it from a backup.)

Ask: remove only ModelType=PCBLIB implementations, or document that every model goes. A safe way to change a footprint link by script is to edit the PCBLIB implementation in place (Impl.ModelName, ClearAllDatafileLinks, AddDataFileLink(name, '', 'PCBLIB')).

Also noted while building a footprint (smaller)

  • altium_edit_footprint graphics: {layer:"F.SilkS", mode:"replace"} clears the layer, but none of the item shapes I tried (items, lines, circles, objects or arrays) added anything. The accepted shape isn't documented in the skill.
  • altium_library_views with a PcbLib libraryPath and a footprint name in parts returned success:false. The same call through the SchLib symbol name works.
  • altium_generate_body ignores pins: 2 (sot23 stays 3 pins, soic stays 8). A two-lead gull-wing body only comes out by setting e: 0, so the leads overlap.
Colby Knox ·

Thanks for the detailed digging, and sorry about the lost simulation model.

You're right on both counts, and we're fixing them now:

  • altium_sch_place_part and altium_create_part_project will place the library part through Altium's own library placement, so it keeps its implementations, parameters, part count and identity.
  • altium_set_models will replace only the footprint (PCBLIB) models and leave SIM, STRESS and any other models alone.

We'll also look at the three smaller ones: the graphics shape in altium_edit_footprint, altium_library_views with a PcbLib, and altium_generate_body ignoring pins. Your notes on adding a SPICE model are going into the docs. We'll post here when the fixes ship.

Colby Knox marked this in progress ·
Colby Knox ·

Fixed in altium-bridge 0.2.114, public now. Adom Bridge picks it up on its next update check.

Placement keeps the library part intact. altium_sch_place_part, altium_create_part_project, altium_place_on_sch and altium_build_schematic now place through SchServer.LoadComponentFromLibrary, as you found. On a test symbol with PCBLIB, SIM and STRESS models, the placed part keeps:

  • all of its models;
  • exactly its 16 own parameters, with nothing from the models copied onto it and no Netlist text on the sheet;
  • its part count and its DesignItemId.

The reply now lists the part's models and says how it was placed: placement: "library". If Altium can't load the library, it falls back to the old rebuild and says placement: "rebuilt". The rebuild now copies only the part's own parameters.

A footprint named in the call becomes the current footprint: the part's own of that name if it has one, otherwise a new link. Its other footprints stay as alternatives.

altium_set_models replaces only footprint (PCBLIB) models. It answers with what it left, e.g. kept: ["SIM", "STRESS"]. Sorry again that it cost you your model.

The smaller ones:

  • altium_edit_footprint: shapes go in shapes: [{type: line|arc|rect|circle|poly, ...}], for example {type: "line", start: [x, y], end: [x, y]}. A graphics entry with no shapes is now refused, naming the keys it didn't read, and nothing changes. Before, a replace cleared the layer and drew nothing.
  • altium_library_views on a .PcbLib gives the footprint and 3D views. A view the library can't have is marked skipped instead of failing the call.
  • altium_generate_body: the engine reads pins inside dimensionsMm. A pins given beside family is now read too, and the reply says so. {family: "sot23", pins: 2} gives a body with two leads.

Your notes on adding a SPICE model (the dialog form that reaches the IntLib, cleaning the .mdl, the diode node order) are now in the schematic skill. A verb to add a SIM model is a separate decision; we'll come back to you on it.

Colby Knox ·

The verb you suggested is in altium-bridge 0.2.115, on the insiders channel now. It reaches everyone with the next public release.

altium_add_sim_model {libraryPath: "<your .SchLib>", symbolName: "<symbol>", modelPath: "<vendor .lib/.mdl on the PC>"}
  • It reads the .MODEL or .SUBCKT (diodes, BJTs, MOSFETs, JFETs, subcircuits). It writes a clean copy beside the library, without the vendor's title line, and puts it on the symbol in the dialog's form.
  • Pins: a pin named for its role (A/K, C/B/E, D/G/S/B) goes to its SPICE node whatever its number. So a diode with its cathode on pin 1 maps itself as you described: 1 to node 2, 2 to node 1. For anything else, pinMap: {"1": 2, "2": 1} sets it, and dryRun shows the plan first.
  • An encrypted model ($CDNENCSTART, .PROT) is refused by name.

Your measurements pointed straight at the difference. A model linked by its full path with kind mdl in lower case, with no component-library or locked-link flags, and with Kind/SubKind/Spice Prefix/Netlist on the model, compiles into the IntLib: MDL/0.mdl and a SIM row in LibCrossRef.Txt. The .mdl didn't need to be a LibPkg document, and the .MODEL values didn't need to be copied in as parameters. A link with kind MDL (upper case) saved and simulated but didn't pack.

Tested with a 1N4148 on a two-pin symbol with its cathode on pin 1:

  • The IntLib packed the model on Altium Designer 26.11.1 and on Develop.
  • Placed in Altium's Simulation Quick Start amplifier, the netlist read DD9 out 0 1N4148 (anode on OUT), and the operating point clamped OUT to 0.719 V.
Colby Knox ·

altium-bridge 0.2.115 is public now, with altium_add_sim_model. Adom Bridge picks it up on its next update check.

MartyPM ·

Thx Colby for all your super-responsive fixes... :)

Colby Knox ·

@MartyPM Happy to help! And thank you for all of the feedback and bug reports

Log in to reply.