From 99f6a029e46eba3497b6593bd0122d80df3c2986 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Sun, 28 Jul 2024 00:37:12 -0400 Subject: [PATCH] Adds support for hierarchical sheets. Recursively proceses hierarchical sheets. --- schematicexport.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/schematicexport.py b/schematicexport.py index 00b67e5..ecec273 100644 --- a/schematicexport.py +++ b/schematicexport.py @@ -207,10 +207,8 @@ def _update_schematic8(self, path): with open(path, encoding="utf-8") as f: lines = f.readlines() - if os.path.exists(path + "_old"): - os.remove(path + "_old") - os.rename(path, path + "_old") partSection = False + files_seen = set() # keeps sheet files already processed. for i in range(0, len(lines) - 1): inLine = lines[i].rstrip() @@ -231,7 +229,7 @@ def _update_schematic8(self, path): value = m.group(2) lastLcsc = value if newLcsc not in (lastLcsc, ""): - self.logger.info("Updating %s on %s", newLcsc, lastRef) + self.logger.info("Updating %s on %s in %s", newLcsc, lastRef, path) outLine = outLine.replace( '"' + lastLcsc + '"', '"' + newLcsc + '"' ) @@ -246,6 +244,12 @@ def _update_schematic8(self, path): if value == part[0]: newLcsc = part[3] break + if key == "Sheetfile": + file_name = m.group(2) + if file_name not in files_seen: + files_seen.add(file_name) + dir_name = os.path.dirname(path) + self._update_schematic8(os.path.join(dir_name, file_name)) # if we hit the pin section without finding a LCSC property, add it m3 = pinRx.search(inLine) if m3 and partSection: @@ -264,6 +268,9 @@ def _update_schematic8(self, path): lastRef = "" newlines.append(outLine) newlines.append(lines[len(lines) - 1].rstrip()) + if os.path.exists(path + "_old"): + os.remove(path + "_old") + os.rename(path, path + "_old") with open(path, "w", encoding="utf-8") as f: for line in newlines: f.write(line + "\n")