Kommentare und Dokumentation aktualisiert, um Schreibfehler zu korrigieren. Radius der Kreiselkreise von 1000 mm auf 400 mm geändert. Ausgabe-DXF-Pfad jetzt dynamisch basierend auf dem CSV-Dateinamen.
This commit is contained in:
+13
-13
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
placeblocks.py
|
||||
Erzeugt DXF‑Elemente aus einer Rule‑Designer‑CSV.
|
||||
Einfache Formen (z. B. "ILS 2.0 Kreisel") werden direkt konstruiert,
|
||||
komplexe per Blockreferenz aus einer DXF‑Bibliothek eingefügt.
|
||||
Erzeugt DXF-Elemente aus einer RuleDesigner-CSV.
|
||||
Einfache Formen (z.B. "ILS 2.0 Kreisel") werden direkt konstruiert,
|
||||
komplexe per Blockreferenz aus einer DXF-Bibliothek eingefügt.
|
||||
"""
|
||||
|
||||
import os
|
||||
@@ -17,11 +17,11 @@ from pathlib import Path
|
||||
|
||||
# --------------------------------------------------------- Konstante Parameter
|
||||
ATTR_TAG = "TeileId" # Attributtag im Block
|
||||
RADIUS = 1000 # Radius der Kreiselkreise (mm)
|
||||
RADIUS = 400 # Radius der Kreiselkreise (mm)
|
||||
|
||||
# --------------------------------------------------------- Hilfsfunktionen
|
||||
def check_environment_var(env_str: str) -> Path:
|
||||
"""Liefert Path aus Umgebungsvariable oder beendet mit Fehlermeldung."""
|
||||
"""Liefert Path aus Umgebungsvariable oder beendet mit Fehlermeldung."""
|
||||
out_path = os.environ.get(env_str)
|
||||
if out_path:
|
||||
return Path(out_path)
|
||||
@@ -29,7 +29,7 @@ def check_environment_var(env_str: str) -> Path:
|
||||
sys.exit(1)
|
||||
|
||||
def extract_coords(planquadrat: str) -> tuple[float, float]:
|
||||
"""Extrahiert X/Y‑Koordinaten aus Planquadrat‑String."""
|
||||
"""Extrahiert X/Y Koordinaten aus PlanquadratString."""
|
||||
m = re.search(r"X:(\d+[\.,]?\d*)\s+Y:(\d+[\.,]?\d*)", planquadrat)
|
||||
if not m:
|
||||
raise ValueError(f"Koordinaten nicht gefunden in: '{planquadrat}'")
|
||||
@@ -37,7 +37,7 @@ def extract_coords(planquadrat: str) -> tuple[float, float]:
|
||||
return float(x.replace(",", ".")), float(y.replace(",", "."))
|
||||
|
||||
def parse_merkmale(merkmale_str: str) -> dict:
|
||||
"""Parst Merkmale‑JSON‑String in dict; bei Fehler → leeres Dict."""
|
||||
"""Parst Merkmale-JSON-String in dict; bei Fehler → leeres Dict."""
|
||||
try:
|
||||
return json.loads(merkmale_str)
|
||||
except json.JSONDecodeError:
|
||||
@@ -79,7 +79,7 @@ def build_simple_shape(msp, teileart: str, x: float, y: float,
|
||||
raise NotImplementedError(f"Einfache Form '{teileart}' nicht implementiert.")
|
||||
|
||||
def load_simple_types(cfg_path: Path) -> set[str]:
|
||||
"""Lädt die Liste der einfachen TeileArt‑Namen aus .cfg."""
|
||||
"""Lädt die Liste der einfachen TeileArtNamen aus .cfg."""
|
||||
cfg = configparser.ConfigParser()
|
||||
cfg.read(cfg_path)
|
||||
names = cfg.get("simple_types", "shape_names", fallback="")
|
||||
@@ -154,11 +154,11 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path,
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Plaziert Anlagenkomponenten aus Rule‑Designer CSV.")
|
||||
parser.add_argument("-f", "--file", required=True, help="CSV‑Datei (Name oder Pfad)", metavar="input.csv")
|
||||
description="Plaziert Anlagenkomponenten aus RuleDesigner CSV.")
|
||||
parser.add_argument("-f", "--file", required=True, help="CSV-Datei (Name oder Pfad)", metavar="input.csv")
|
||||
parser.add_argument("-c", "--config", help="CFG mit einfachen Formen", metavar="shapes.cfg")
|
||||
parser.add_argument("-l", "--lib", help="DXF‑Bibliothek mit Blöcken", metavar="bibliothek.dxf")
|
||||
parser.add_argument("-o", "--output", help="Ziel‑DXF (Standard: PROJECT_WORK/anlage.dxf)", metavar="anlage.dxf")
|
||||
parser.add_argument("-l", "--lib", help="DXF-Bibliothek mit Blöcken", metavar="bibliothek.dxf")
|
||||
parser.add_argument("-o", "--output", help="Ziel-DXF (Standard: PROJECT_WORK/anlage.dxf)", metavar="anlage.dxf")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="mehr Ausgaben anzeigen")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -175,6 +175,6 @@ if __name__ == "__main__":
|
||||
|
||||
cfg_path = Path(args.config) if args.config else config_dir / "shapes.cfg"
|
||||
lib_path = Path(args.lib) if args.lib else data_dir / "bibliothek.dxf"
|
||||
output_path = Path(args.output) if args.output else work_dir / "anlage.dxf"
|
||||
output_path = Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.dxf")
|
||||
|
||||
main(csv_path, lib_path, cfg_path, output_path, verbose=args.verbose)
|
||||
|
||||
Reference in New Issue
Block a user