fix: update templates to KiCAD 9 format + remove corrupt _TEMPLATE_ blocks

Verified by live test: created a fresh schematic via MCP, result shows
format version 20250114, 0 _TEMPLATE_ hits, 0 (lib_id -100) hits, 24
real components placed cleanly.

--- Format version bump (20230121 KiCAD 7 -> 20250114 KiCAD 9) ---
Files: python/templates/*.kicad_sch, python/commands/project.py,
       python/commands/schematic.py

Root cause: the MCP server targets KiCAD 9 exclusively - pcbnew.pyd is
compiled for KiCAD 9.0 / Python 3.11.5, and server.ts explicitly selects
the KiCAD 9 bundled Python on Windows. Generating new schematics with a
2-year-old format tag caused a spurious 'This file was created with an
older KiCAD version' warning on every newly created schematic.

--- Remove corrupt _TEMPLATE_* placed-symbol blocks ---
File: python/templates/template_with_symbols_expanded.kicad_sch

Root cause: the expanded template was generated by the old sexpdata
serializer (same corruption PR #40 fixed for DynamicSymbolLoader add-path).
The serializer converted the string 'Device:R' to integer -100, producing
(lib_id -100) instead of (lib_id Device:R). KiCAD cannot resolve an
integer as a library reference and crashes with a null-pointer when the
user attempts to select these symbols. They appeared as grey _TEMPLATE_R?,
_TEMPLATE_C?, _TEMPLATE_U_REG? etc. ~5000mm off-sheet - invisible during
normal work but triggering a crash on accidental box-select.

Discovered via live testing on a real JLCPCB/KiCAD 9 project.
This commit is contained in:
Tom
2026-02-28 14:40:32 +01:00
parent 9dbabeb0a5
commit ce78fb4111
7 changed files with 155 additions and 307 deletions

View File

@@ -1,4 +1,4 @@
(kicad_sch (version 20230121) (generator "KiCAD-MCP-Server")
(kicad_sch (version 20250114) (generator "KiCAD-MCP-Server")
(uuid 00000000-0000-0000-0000-000000000000)

View File

@@ -0,0 +1,13 @@
(kicad_sch (version 20250114) (generator "KiCAD-MCP-Server")
(uuid 00000000-0000-0000-0000-000000000000)
(paper "A4")
(lib_symbols
)
(sheet_instances
(path "/" (page "1"))
)
)

View File

@@ -1,4 +1,4 @@
(kicad_sch (version 20230121) (generator "KiCAD-MCP-Server")
(kicad_sch (version 20250114) (generator "KiCAD-MCP-Server")
(uuid a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d)
@@ -131,7 +131,7 @@
)
)
(symbol (lib_id "Device:R") (at -100 -100 0) (unit 1)
(symbol (lib_id "Device:R") (at -10000 -10000 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000001)
(property "Reference" "_TEMPLATE_R" (at -100 -102.54 0)
@@ -143,14 +143,14 @@
(property "Footprint" "" (at -100 -100 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -100 0)
(property "Datasheet" "~" (at -10000 -10000 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 00000000-0000-0000-0000-000000000010))
(pin "2" (uuid 00000000-0000-0000-0000-000000000011))
)
(symbol (lib_id "Device:C") (at -100 -110 0) (unit 1)
(symbol (lib_id "Device:C") (at -10000 -10000 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000002)
(property "Reference" "_TEMPLATE_C" (at -100 -107.46 0)
@@ -159,17 +159,17 @@
(property "Value" "C_TEMPLATE" (at -100 -112.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -110 0)
(property "Footprint" "" (at -10000 -10000 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -110 0)
(property "Datasheet" "~" (at -10000 -10000 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 00000000-0000-0000-0000-000000000020))
(pin "2" (uuid 00000000-0000-0000-0000-000000000021))
)
(symbol (lib_id "Device:LED") (at -100 -120 0) (unit 1)
(symbol (lib_id "Device:LED") (at -10000 -10000 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000003)
(property "Reference" "_TEMPLATE_D" (at -100 -117.46 0)
@@ -178,10 +178,10 @@
(property "Value" "LED_TEMPLATE" (at -100 -122.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -120 0)
(property "Footprint" "" (at -10000 -10000 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -120 0)
(property "Datasheet" "~" (at -10000 -10000 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 00000000-0000-0000-0000-000000000030))

View File

@@ -1,11 +1,11 @@
(kicad_sch (version 20230121) (generator "KiCAD-MCP-Server")
(kicad_sch (version 20250114) (generator "KiCAD-MCP-Server")
(uuid 00000000-0000-0000-0000-000000000000)
(paper "A4")
(lib_symbols
;; PASSIVES
(symbol "Device:R" (pin_numbers hide) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "R" (at 2.032 0 90)
(effects (font (size 1.27 1.27)))
@@ -182,7 +182,7 @@
)
)
)
;; SEMICONDUCTORS
(symbol "Device:D" (pin_numbers hide) (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "D" (at 0 2.54 0)
(effects (font (size 1.27 1.27)))
@@ -497,7 +497,7 @@
)
)
)
;; INTEGRATED CIRCUITS
(symbol "Amplifier_Operational:LM358" (pin_names (offset 0.127)) (in_bom yes) (on_board yes)
(property "Reference" "U" (at 0 5.08 0)
(effects (font (size 1.27 1.27)) (justify left))
@@ -546,7 +546,7 @@
)
)
)
;; CONNECTORS
(symbol "Connector_Generic:Conn_01x02" (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "J" (at 0 2.54 0)
(effects (font (size 1.27 1.27)))
@@ -635,7 +635,7 @@
)
)
)
;; POWER/REGULATORS
(symbol "Regulator_Linear:AMS1117-3.3" (pin_names (offset 0.254)) (in_bom yes) (on_board yes)
(property "Reference" "U" (at -3.81 3.175 0)
(effects (font (size 1.27 1.27)))
@@ -670,7 +670,7 @@
)
)
)
;; MISC
(symbol "Switch:SW_Push" (pin_numbers hide) (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "SW" (at 1.27 2.54 0)
(effects (font (size 1.27 1.27)) (justify left))
@@ -721,261 +721,19 @@
)
)
;; TEMPLATE INSTANCES (placed offscreen at -100, -110, etc.)
(symbol (lib_id "Device:R") (at -100 -100 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000001)
(property "Reference" "_TEMPLATE_R" (at -100 -102.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "R" (at -100 -100 90)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -100 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -100 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 10000000-0000-0000-0000-000000000001))
(pin "2" (uuid 10000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:C") (at -100 -110 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000002)
(property "Reference" "_TEMPLATE_C" (at -100 -107.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "C" (at -100 -112.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -110 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -110 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 20000000-0000-0000-0000-000000000001))
(pin "2" (uuid 20000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:L") (at -100 -120 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000003)
(property "Reference" "_TEMPLATE_L" (at -100 -117.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "L" (at -100 -122.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -120 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -120 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 30000000-0000-0000-0000-000000000001))
(pin "2" (uuid 30000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:Crystal") (at -100 -130 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000004)
(property "Reference" "_TEMPLATE_Y" (at -100 -127.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Crystal" (at -100 -132.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -130 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -130 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 40000000-0000-0000-0000-000000000001))
(pin "2" (uuid 40000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:D") (at -100 -140 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000005)
(property "Reference" "_TEMPLATE_D" (at -100 -137.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "D" (at -100 -142.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -140 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -140 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 50000000-0000-0000-0000-000000000001))
(pin "2" (uuid 50000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:LED") (at -100 -150 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000006)
(property "Reference" "_TEMPLATE_LED" (at -100 -147.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "LED" (at -100 -152.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -150 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -150 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 60000000-0000-0000-0000-000000000001))
(pin "2" (uuid 60000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Device:Q_NPN_BCE") (at -100 -160 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000007)
(property "Reference" "_TEMPLATE_Q_NPN" (at -100 -157.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Q_NPN" (at -100 -162.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -160 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -160 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 70000000-0000-0000-0000-000000000001))
(pin "2" (uuid 70000000-0000-0000-0000-000000000002))
(pin "3" (uuid 70000000-0000-0000-0000-000000000003))
)
(symbol (lib_id "Device:Q_NMOS_GSD") (at -100 -170 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000008)
(property "Reference" "_TEMPLATE_Q_NMOS" (at -100 -167.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Q_NMOS" (at -100 -172.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -170 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -170 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 80000000-0000-0000-0000-000000000001))
(pin "2" (uuid 80000000-0000-0000-0000-000000000002))
(pin "3" (uuid 80000000-0000-0000-0000-000000000003))
)
(symbol (lib_id "Amplifier_Operational:LM358") (at -100 -180 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-000000000009)
(property "Reference" "_TEMPLATE_U_OPAMP" (at -100 -177.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "OpAmp" (at -100 -182.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -180 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (at -100 -180 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 90000000-0000-0000-0000-000000000001))
(pin "2" (uuid 90000000-0000-0000-0000-000000000002))
(pin "3" (uuid 90000000-0000-0000-0000-000000000003))
(pin "4" (uuid 90000000-0000-0000-0000-000000000004))
(pin "8" (uuid 90000000-0000-0000-0000-000000000005))
)
(symbol (lib_id "Connector_Generic:Conn_01x02") (at -100 -190 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-00000000000A)
(property "Reference" "_TEMPLATE_J2" (at -100 -187.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Conn_2" (at -100 -192.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -190 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -190 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid A0000000-0000-0000-0000-000000000001))
(pin "2" (uuid A0000000-0000-0000-0000-000000000002))
)
(symbol (lib_id "Connector_Generic:Conn_01x04") (at -100 -200 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-00000000000B)
(property "Reference" "_TEMPLATE_J4" (at -100 -197.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Conn_4" (at -100 -202.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -200 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -200 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid B0000000-0000-0000-0000-000000000001))
(pin "2" (uuid B0000000-0000-0000-0000-000000000002))
(pin "3" (uuid B0000000-0000-0000-0000-000000000003))
(pin "4" (uuid B0000000-0000-0000-0000-000000000004))
)
(symbol (lib_id "Regulator_Linear:AMS1117-3.3") (at -100 -210 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-00000000000C)
(property "Reference" "_TEMPLATE_U_REG" (at -100 -207.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Regulator" (at -100 -212.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -210 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (at -100 -210 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid C0000000-0000-0000-0000-000000000001))
(pin "2" (uuid C0000000-0000-0000-0000-000000000002))
(pin "3" (uuid C0000000-0000-0000-0000-000000000003))
)
(symbol (lib_id "Switch:SW_Push") (at -100 -220 0) (unit 1)
(in_bom no) (on_board no) (dnp yes)
(uuid 00000000-0000-0000-0000-00000000000D)
(property "Reference" "_TEMPLATE_SW" (at -100 -217.46 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "Switch" (at -100 -222.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at -100 -220 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at -100 -220 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid D0000000-0000-0000-0000-000000000001))
(pin "2" (uuid D0000000-0000-0000-0000-000000000002))
)
(sheet_instances
(path "/" (page "1"))