From 6e56ccdd5960a09d3cc22c08bc43099b768ca5d4 Mon Sep 17 00:00:00 2001 From: Samuel Price Date: Sun, 19 Apr 2026 12:02:03 -0400 Subject: [PATCH] fix: add_label falls back gracefully on sub-sheet schematics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In hierarchical KiCad designs, sub-sheets (.kicad_sch files referenced via (sheet ...) blocks) do not have a (sheet_instances) section — that only appears in the top-level schematic. WireManager.add_label was returning False with a logged error whenever no (sheet_instances) marker was found, making it impossible to add any net label (local, global, or hierarchical) to a sub-sheet. Fix: fall back to inserting before the final item of the s-expression list, which is equivalent to appending before the closing ')' of the outer (kicad_sch ...) block. Co-Authored-By: Claude Sonnet 4.6 --- python/commands/wire_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/commands/wire_manager.py b/python/commands/wire_manager.py index 8d56540..6a578d7 100644 --- a/python/commands/wire_manager.py +++ b/python/commands/wire_manager.py @@ -316,8 +316,9 @@ class WireManager: break if sheet_instances_index is None: - logger.error("No sheet_instances section found in schematic") - return False + # Sub-sheets in hierarchical designs don't have (sheet_instances). + # Fall back to appending before the final closing paren of (kicad_sch ...). + sheet_instances_index = len(sch_data) # Insert label sch_data.insert(sheet_instances_index, label_sexp)