Files
plant2dxf/lib/svg2dxf.py
T

34 lines
1.1 KiB
Python

import os
import subprocess
import sys
# Hilfsfunktion wie in plant2dxf.py
def check_environment_var(env_str: str, fallback: str) -> str:
out_path = os.environ.get(env_str)
if out_path:
return out_path
print(f"[WARN] Umgebungsvariable {env_str} ist nicht gesetzt oder leer. Verwende '{fallback}'.")
return fallback
# Verzeichnisse über Umgebungsvariablen oder Fallback
INPUT_DIR = os.path.join(check_environment_var("PROJECT_WORK", "."), "input_svg")
OUTPUT_DIR = os.path.join(check_environment_var("PROJECT_WORK", "."), "converted_dxfs")
INKSCAPE = "inkscape" # ggf. vollständiger Pfad angeben
os.makedirs(OUTPUT_DIR, exist_ok=True)
for filename in os.listdir(INPUT_DIR):
if filename.lower().endswith((".svg", ".xml")):
in_path = os.path.join(INPUT_DIR, filename)
name_wo_ext = os.path.splitext(filename)[0]
out_path = os.path.join(OUTPUT_DIR, name_wo_ext + ".dxf")
print(f"Konvertiere: {filename}{out_path}")
subprocess.run([
INKSCAPE,
in_path,
"--export-type=dxf",
f"--export-filename={out_path}"
], check=True)