Load user symbol libraries from a directory's ``*.svg`` files, AFTER the system bundle, so they ADD new symbols or REDEFINE (override) system ones. Files whose stem is in ``exclude_stems`` are skipped — e.g. a generated subcircuit block symbol, which pairs with a `` .li
(self, directory, exclude_stems=())
| 349 | return skipped |
| 350 | |
| 351 | def add_user_library(self, directory, exclude_stems=()) -> None: |
| 352 | """Load user symbol libraries from a directory's ``*.svg`` files, AFTER |
| 353 | the system bundle, so they ADD new symbols or REDEFINE (override) system |
| 354 | ones. Files whose stem is in ``exclude_stems`` are skipped — e.g. a |
| 355 | generated subcircuit block symbol, which pairs with a ``<name>.lib`` and |
| 356 | loads only when its block is placed, never into a fresh schematic.""" |
| 357 | directory = Path(directory) |
| 358 | if not directory.is_dir(): |
| 359 | return |
| 360 | parser = ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)) |
| 361 | for svg_file in sorted(directory.glob("*.svg")): |
| 362 | if svg_file.stem in exclude_stems: |
| 363 | continue |
| 364 | try: |
| 365 | root = ET.parse(svg_file, parser).getroot() |
| 366 | except ET.ParseError: |
| 367 | continue |
| 368 | for g in root.iter(f"{{{SVG_NS}}}g"): |
| 369 | if g.get("id") and g.get("data-prefix"): |
| 370 | self._add_g(g, svg_file.name, override=True) |
| 371 | |
| 372 | def write_bundle(self, names, path) -> None: |
| 373 | """Write the given symbols' raw <g> definitions to a bundle SVG, so the |