fix: add_label falls back gracefully on sub-sheet schematics

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 <noreply@anthropic.com>
This commit is contained in:
Samuel Price
2026-04-19 12:02:03 -04:00
parent 3d996427ee
commit 6e56ccdd59

View File

@@ -316,8 +316,9 @@ class WireManager:
break break
if sheet_instances_index is None: if sheet_instances_index is None:
logger.error("No sheet_instances section found in schematic") # Sub-sheets in hierarchical designs don't have (sheet_instances).
return False # Fall back to appending before the final closing paren of (kicad_sch ...).
sheet_instances_index = len(sch_data)
# Insert label # Insert label
sch_data.insert(sheet_instances_index, label_sexp) sch_data.insert(sheet_instances_index, label_sexp)