diff --git a/lib/plant2dxf.py b/lib/plant2dxf.py index 3fc2f4f..fcea5a3 100644 --- a/lib/plant2dxf.py +++ b/lib/plant2dxf.py @@ -347,26 +347,7 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, output_path: Path, verbose=False, logger=None): # Bibliothek nur laden, wenn Datei existiert - lib_doc = None - if lib_path.exists(): - try: - lib_doc = ezdxf.readfile(lib_path) - if verbose: - logger.info(f"[INFO] Bibliothek geladen: {lib_path}") if logger else print(f"[INFO] Bibliothek geladen: {lib_path}") - except Exception as e: - msg = f"Fehler beim Lesen der Bibliothek '{lib_path}': {e}" - if logger: - logger.error(msg) - else: - print(msg) - sys.exit(1) - else: - msg = f"[INFO] Keine Bibliothek gefunden unter {lib_path}." - if logger: - logger.warning(msg) - else: - print(msg) - sys.exit(1) + check_dxflibrary_path(lib_path, verbose, logger) # Neue Ziel­zeichnung (DXF R2018) doc = ezdxf.new(dxfversion="R2018") @@ -383,6 +364,9 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, print(msg) sys.exit(1) + blocklib_dir = data_dir / "block_libraries" + lib_docs = dict() + # Verarbeitung der Blöcke with csv_path.open(newline="", encoding="utf-8") as fh: reader = csv.DictReader(fh, delimiter=';') @@ -428,7 +412,7 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, # Funktions-Dispatch: handle_ (mit _ statt Leerzeichen und Punkten, alles klein) func_name = f'handle_{normalize_func_name(teileart)}' handler = globals().get(func_name) - symbols = get_shape_cfg(teileart, shapes_cfg_path, logger=logger) + symbols = get_shape_cfg(teileart, cfg_path, logger=logger) # Mapping für Omniflo-Typen if func_name.startswith('handle_omniflo'): handler = globals().get('handle_omniflo') @@ -449,6 +433,28 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, else: print(f"[DONE] DXF gespeichert unter: {output_path}") +def check_dxflibrary_path(lib_path, verbose, logger): + lib_doc = None + if lib_path.exists(): + try: + lib_doc = ezdxf.readfile(lib_path) + if verbose: + logger.info(f"[INFO] Bibliothek geladen: {lib_path}") if logger else print(f"[INFO] Bibliothek geladen: {lib_path}") + except Exception as e: + msg = f"Fehler beim Lesen der Bibliothek '{lib_path}': {e}" + if logger: + logger.error(msg) + else: + print(msg) + sys.exit(1) + else: + msg = f"[INFO] Keine Bibliothek gefunden unter {lib_path}." + if logger: + logger.error(msg) + else: + print(msg) + sys.exit(1) + if __name__ == "__main__": parser = argparse.ArgumentParser( description="Plaziert Anlagenkomponenten aus RuleDesigner CSV.")