Compare commits
2 Commits
a0e3c7a04f
...
91fffadc1f
| Author | SHA1 | Date | |
|---|---|---|---|
| 91fffadc1f | |||
| 4075cef30e |
File diff suppressed because it is too large
Load Diff
+26
-3
@@ -43,7 +43,7 @@ if __name__ == "__main__":
|
|||||||
# Argumentparser für Kommandozeilenoptionen
|
# Argumentparser für Kommandozeilenoptionen
|
||||||
parser = argparse.ArgumentParser(description="SVG/XML zu DXF Konverter")
|
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('-i', '--input', type=str, help='Input-Verzeichnis mit SVG/XML-Dateien')
|
||||||
parser.add_argument('-n', '--name', required=True, type=str, help='Name der zu erzeugenden Bibliothek')
|
parser.add_argument('-n', '--name', required=False, type=str, help='Name der zu erzeugenden Bibliothek (optional, wird sonst abgefragt)')
|
||||||
parser.add_argument('-k', '--keep', action="store_true", help='Behalte converted_dxf Ordner. Sonst Löschen nach erfolgreicher Bibliothekserstellung')
|
parser.add_argument('-k', '--keep', action="store_true", help='Behalte converted_dxf Ordner. Sonst Löschen nach erfolgreicher Bibliothekserstellung')
|
||||||
|
|
||||||
if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"):
|
if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"):
|
||||||
@@ -52,6 +52,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if not args.name:
|
||||||
|
args.name = input("Bitte Namen der zu erzeugenden Bibliothek eingeben: ").strip()
|
||||||
|
if not args.name:
|
||||||
|
print("Fehler: Kein Name angegeben. Beende.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Verzeichnisse über Umgebungsvariablen oder Fallback
|
# Verzeichnisse über Umgebungsvariablen oder Fallback
|
||||||
if args.input:
|
if args.input:
|
||||||
INPUT_DIR = args.input
|
INPUT_DIR = args.input
|
||||||
@@ -106,8 +112,20 @@ if __name__ == "__main__":
|
|||||||
# Platzierung in Reihen und Spalten
|
# Platzierung in Reihen und Spalten
|
||||||
msp.add_blockref(name, insert=(x_offset, y_offset))
|
msp.add_blockref(name, insert=(x_offset, y_offset))
|
||||||
# Text mit Blocknamen über dem Block
|
# Text mit Blocknamen über dem Block
|
||||||
text_y = y_offset + 150 # 150 Einheiten über dem Block
|
text_y = y_offset + 175 # 175 Einheiten über dem Block
|
||||||
msp.add_text(name, dxfattribs={'height': 20, 'insert': (x_offset-150, text_y)})
|
max_len = 9
|
||||||
|
text_height = 20
|
||||||
|
line_spacing = 22 # Abstand zwischen den zwei Textzeilen
|
||||||
|
|
||||||
|
if len(name) > max_len:
|
||||||
|
first_line = name[:max_len]
|
||||||
|
second_line = name[max_len:]
|
||||||
|
# obere Zeile
|
||||||
|
msp.add_text(first_line, dxfattribs={'height': text_height, 'insert': (x_offset - 150, text_y)})
|
||||||
|
# untere Zeile, etwas niedriger (y kleiner)
|
||||||
|
msp.add_text(second_line, dxfattribs={'height': text_height, 'insert': (x_offset - 150, text_y - line_spacing)})
|
||||||
|
else:
|
||||||
|
msp.add_text(name, dxfattribs={'height': text_height, 'insert': (x_offset - 150, text_y)})
|
||||||
blocks_in_row += 1
|
blocks_in_row += 1
|
||||||
x_offset += 350 # Abstand zwischen Blöcken in einer Reihe
|
x_offset += 350 # Abstand zwischen Blöcken in einer Reihe
|
||||||
if blocks_in_row == 20:
|
if blocks_in_row == 20:
|
||||||
@@ -116,6 +134,11 @@ if __name__ == "__main__":
|
|||||||
y_offset -= 500 # Neue Zeile, nach unten versetzt
|
y_offset -= 500 # Neue Zeile, nach unten versetzt
|
||||||
|
|
||||||
print(f"Bibliotheks-DXF gespeichert: {OUTPUT_FILE} \n")
|
print(f"Bibliotheks-DXF gespeichert: {OUTPUT_FILE} \n")
|
||||||
|
|
||||||
|
output_dir = os.path.dirname(OUTPUT_FILE)
|
||||||
|
if not os.path.exists(output_dir):
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
doc.saveas(OUTPUT_FILE)
|
doc.saveas(OUTPUT_FILE)
|
||||||
|
|
||||||
if not args.keep:
|
if not args.keep:
|
||||||
|
|||||||
+13
-9
@@ -2,7 +2,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import time
|
||||||
# Hilfsfunktion wie in plant2dxf.py
|
# Hilfsfunktion wie in plant2dxf.py
|
||||||
|
|
||||||
def check_environment_var(env_str: str, fallback: str) -> str:
|
def check_environment_var(env_str: str, fallback: str) -> str:
|
||||||
@@ -44,16 +44,20 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||||
|
|
||||||
for filename in os.listdir(INPUT_DIR):
|
files = [f for f in os.listdir(INPUT_DIR) if f.lower().endswith((".svg", ".xml"))]
|
||||||
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}")
|
for filename in files:
|
||||||
|
input_path = os.path.join(INPUT_DIR, filename)
|
||||||
|
output_path = os.path.join(OUTPUT_DIR, os.path.splitext(filename)[0] + ".dxf")
|
||||||
|
|
||||||
|
print(f"Konvertiere: {input_path} → {output_path}")
|
||||||
|
try:
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
INKSCAPE,
|
INKSCAPE,
|
||||||
in_path,
|
input_path,
|
||||||
"--export-type=dxf",
|
"--export-type=dxf",
|
||||||
f"--export-filename={out_path}"
|
f"--export-filename={output_path}"
|
||||||
], check=True)
|
], check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"[FEHLER] Inkscape-Absturz bei {filename}: {e}")
|
||||||
|
time.sleep(0.5) # kleine Pause zur Entlastung von RAM/GTK
|
||||||
|
|||||||
Reference in New Issue
Block a user