Neue Batch-Dateien dxfs2lib.bat und svg2dxf.bat hinzugefügt zur Ausführung der Skripte für die Konvertierung von DXF und SVG. Erweiterung der dxf2lib.py und svg2dxf.py um Kommandozeilenargumente für Eingabe- und Ausgabeverzeichnisse.

This commit is contained in:
2025-07-29 12:04:02 +02:00
parent 90ddb5982f
commit ce0388586f
4 changed files with 181 additions and 17 deletions
+43 -17
View File
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import argparse
# Hilfsfunktion wie in plant2dxf.py
@@ -11,23 +12,48 @@ def check_environment_var(env_str: str, fallback: str) -> str:
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)
if __name__ == "__main__":
# Argumentparser für Kommandozeilenoptionen
parser = argparse.ArgumentParser(description="SVG/XML zu DXF Konverter")
parser.add_argument('-i', '--input', type=str, help='Input-Verzeichnis mit SVG/XML-Dateien')
parser.add_argument('-o', '--output', type=str, help='Output-Verzeichnis für DXF-Dateien')
if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"):
parser.print_help()
sys.exit(0)
args = parser.parse_args()
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")
# Verzeichnisse über Umgebungsvariablen oder Fallback
if args.input:
INPUT_DIR = args.input
print(f"Input-Verzeichnis: {INPUT_DIR}")
else:
INPUT_DIR = os.path.join(check_environment_var("PROJECT_DATA", "."), "svg")
print(f"Kein Input-Verzeichnis angegeben, verwende Standard: {INPUT_DIR}")
print(f"Konvertiere: {filename}{out_path}")
subprocess.run([
INKSCAPE,
in_path,
"--export-type=dxf",
f"--export-filename={out_path}"
], check=True)
if args.output:
OUTPUT_DIR = args.output
print(f"Output-Verzeichnis: {OUTPUT_DIR}")
else:
OUTPUT_DIR = os.path.join(check_environment_var("PROJECT_WORK", "."), "converted_dxfs")
print(f"Kein Output-Verzeichnis angegeben, verwende Standard: {OUTPUT_DIR}")
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)