die Fehler in VarioFoerderer.lsp korrigiert. alle in ILS-LSP verwendete Block Dateien in data/ils/ konsolidiert.

This commit is contained in:
2026-06-02 10:00:36 +02:00
parent acf9f666cc
commit c014ef2f12
96 changed files with 166139 additions and 226 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -18,11 +18,11 @@ AutoLISP-Makros (SSG_LIB) fuer BricsCAD Pro zur automatisierten Erstellung von F
| Verzeichnis | Inhalt | | Verzeichnis | Inhalt |
|---|---| |---|---|
| `Blocks/` | DWG-Bloecke (Vertikalboegen, Stationen, etc.) |
| `Lisp/` | AutoLISP-Makros und Kernbibliotheken | | `Lisp/` | AutoLISP-Makros und Kernbibliotheken |
| `bin/` | Hilfs-Skripte (setenv, on_start.lsp) | | `bin/` | Hilfs-Skripte (setenv, on_start.lsp) |
| `cfg/` | Konfigurationsdateien | | `cfg/` | Konfigurationsdateien |
| `data/` | JSON-Daten, DXF-Quellen, Block-Libraries | | `data/` | JSON-Daten, DXF-Quellen, Block-Libraries |
| `data/ils/` | DWG-Bloecke fuer ILS-Kreisel/Eckrad (AN8, SP8, AP-Typen) |
| `dcl/` | DCL-Dialogdefinitionen | | `dcl/` | DCL-Dialogdefinitionen |
| `doc/` | Dokumentation, Entwicklungsplan | | `doc/` | Dokumentation, Entwicklungsplan |
| `lib/` | Python-Skripte (CSV/Sivas-Export) | | `lib/` | Python-Skripte (CSV/Sivas-Export) |
@@ -55,7 +55,7 @@ Werden via `bin/setenv.bat` gesetzt. Wichtigste:
- AutoLISP-Funktionsnamen: `ssg-*` fuer Kernfunktionen, `C:BEFEHLSNAME` fuer User-Commands - AutoLISP-Funktionsnamen: `ssg-*` fuer Kernfunktionen, `C:BEFEHLSNAME` fuer User-Commands
- Alle Texte in Dateien ohne Umlaute (ae, oe, ue statt ae, oe, ue) - Alle Texte in Dateien ohne Umlaute (ae, oe, ue statt ae, oe, ue)
- Bloecke werden als DWG in `Blocks/` abgelegt, Block-Libraries als DXF in `data/block_libraries/` - Bloecke werden als DWG in `data/ils/` abgelegt, Block-Libraries als DXF in `data/block_libraries/`
- Komponentendaten (Masse, Sivas-IDs) liegen als JSON in `data/json/` - Komponentendaten (Masse, Sivas-IDs) liegen als JSON in `data/json/`
- Sprache im Code und Kommentaren: Deutsch - Sprache im Code und Kommentaren: Deutsch
+284 -222
View File
@@ -17,9 +17,9 @@
) )
) )
;; Pfad zur Koordinaten-Bibliothek ;; Pfad zum Verzeichnis mit den Einzelblock-DXF-Dateien
(if (getenv "DXFM_DATA") (if (getenv "DXFM_DATA")
(setq koordinaten-lib (strcat (getenv "DXFM_DATA") "/block_libraries/ils_library.dwg")) (setq block-pfad (strcat (getenv "DXFM_DATA") "/ils/"))
(progn (progn
(alert "Umgebungsvariable DXFM_DATA nicht gesetzt!\nBitte zuerst bin\\setenv.bat ausfuehren.") (alert "Umgebungsvariable DXFM_DATA nicht gesetzt!\nBitte zuerst bin\\setenv.bat ausfuehren.")
(exit) (exit)
@@ -101,17 +101,36 @@
;; TEIL 4: KS_EIN/KS_AUS EXTRAKTION (KERN-FUNKTION) ;; TEIL 4: KS_EIN/KS_AUS EXTRAKTION (KERN-FUNKTION)
;; ============================================================ ;; ============================================================
;; Grad-Zeichen für Blocknamen ;; Grad-Zeichen fuer Blocknamen
(setq grad-zeichen (chr 176)) (setq grad-zeichen (chr 176))
;; Laedt einen Block aus seiner Einzeldatei, falls noch nicht in der Zeichnung definiert.
;; Blockdatei: block-pfad/<blockname>.dxf
(defun ensure-block-loaded (blockname / block-datei temp-obj)
(if (not (tblsearch "BLOCK" blockname))
(progn
(setq block-datei (strcat block-pfad blockname ".dxf"))
(if (findfile block-datei)
(progn
(setq temp-obj (vla-InsertBlock modelspace
(vlax-3D-point '(0 0 0))
block-datei 1.0 1.0 1.0 0))
(vla-Delete temp-obj)
)
(princ (strcat "\n FEHLER: Blockdatei nicht gefunden: " block-datei))
)
)
)
)
;; Extrahiert KS_EIN und KS_AUS aus einem Block (intern, ohne Cache) ;; Extrahiert KS_EIN und KS_AUS aus einem Block (intern, ohne Cache)
;; Rückgabe: (("KS_EIN" (origin x-end y-end z-end)) ;; Rückgabe: (("KS_EIN" (origin x-end y-end z-end))
;; ("KS_AUS" (origin x-end y-end z-end))) ;; ("KS_AUS" (origin x-end y-end z-end)))
(defun extract-ks-from-block-raw (block-obj / sub-entities sub-obj ks-results (defun extract-ks-from-block-raw (block-obj / sub-entities sub-obj ks-results
ks-ref inner-entities inner-obj origin x-end y-end z-end ks-ref inner-entities inner-obj origin x-end y-end z-end
line-start line-end axis line-len line-vec) line-start line-end axis line-len line-vec)
(dbgf "extract-ks-from-block-raw") ;; (dbgf "extract-ks-from-block-raw")
(dbg block-obj) ;; (dbg block-obj)
(setq ks-results '()) (setq ks-results '())
;; Block explodieren ;; Block explodieren
@@ -167,7 +186,7 @@
(if (not (vlax-erased-p sub-obj)) (vla-Delete sub-obj)) (if (not (vlax-erased-p sub-obj)) (vla-Delete sub-obj))
) )
(dbgreturn ks-results) ks-results
) )
;; Gecachte Version: prueft *ks-cache* anhand Blockname ;; Gecachte Version: prueft *ks-cache* anhand Blockname
@@ -175,18 +194,18 @@
;; zum Einfuegepunkt im Cache gespeichert. Weitere Aufrufe ;; zum Einfuegepunkt im Cache gespeichert. Weitere Aufrufe
;; desselben Blocktyps liefern die Daten ohne Explode. ;; desselben Blocktyps liefern die Daten ohne Explode.
(defun extract-ks-from-block (block-obj / blockname insert-pt cached result ks-rel) (defun extract-ks-from-block (block-obj / blockname insert-pt cached result ks-rel)
(dbgf "extract-ks-from-block") ;; (dbgf "extract-ks-from-block")
(setq blockname (vla-get-Name block-obj)) (setq blockname (vla-get-Name block-obj))
(setq insert-pt (vlax-safearray->list (setq insert-pt (vlax-safearray->list
(vlax-variant-value (vla-get-InsertionPoint block-obj)))) (vlax-variant-value (vla-get-InsertionPoint block-obj))))
(setq cached (assoc blockname *ks-cache*)) (setq cached (assoc blockname *ks-cache*))
(if cached (if cached
(progn (progn
(dbg (strcat " KS-Cache HIT: " blockname)) ;; (dbg (strcat " KS-Cache HIT: " blockname))
(dbgreturn (ks-absolutize (cdr cached) insert-pt)) (ks-absolutize (cdr cached) insert-pt)
) )
(progn (progn
(dbg (strcat " KS-Cache MISS: " blockname)) ;; (dbg (strcat " KS-Cache MISS: " blockname))
(setq result (extract-ks-from-block-raw block-obj)) (setq result (extract-ks-from-block-raw block-obj))
(if result (if result
(progn (progn
@@ -194,7 +213,7 @@
(setq *ks-cache* (cons (cons blockname ks-rel) *ks-cache*)) (setq *ks-cache* (cons (cons blockname ks-rel) *ks-cache*))
) )
) )
(dbgreturn result) result
) )
) )
) )
@@ -203,7 +222,7 @@
;; TEIL 5: PUNKTE-AUSWAHL MIT Z-HÖHE (HIER EINFÜGEN!) ;; TEIL 5: PUNKTE-AUSWAHL MIT Z-HÖHE (HIER EINFÜGEN!)
;; ============================================================ ;; ============================================================
(defun get-3d-point-from-object (msg / ent obj pt variant) (defun get-3d-point-from-object (msg / ent obj pt variant)
(dbgf "get-3d-point-from-object") ;; (dbgf "get-3d-point-from-object")
(princ msg) (princ msg)
(princ "\n >> Objekt (Block) wählen: ") (princ "\n >> Objekt (Block) wählen: ")
(setq ent (entsel)) (setq ent (entsel))
@@ -235,13 +254,13 @@
(setq pt nil) (setq pt nil)
) )
) )
(dbgreturn pt) pt
) )
;; ============================================================ ;; ============================================================
;; TEIL 5: 3D-LINIE AUSWÄHLEN (für Start- und Endpunkt mit Höhe) ;; TEIL 5: 3D-LINIE AUSWÄHLEN (für Start- und Endpunkt mit Höhe)
;; ============================================================ ;; ============================================================
(defun get-line-start-end-points (msg / ent obj start-pt end-pt) (defun get-line-start-end-points (msg / ent obj obj-name start-pt end-pt)
(princ msg) (princ msg)
(princ "\n >> 3D-Linie oder Polylinie wählen (mit Höhendifferenz): ") (princ "\n >> 3D-Linie oder Polylinie wählen (mit Höhendifferenz): ")
(setq ent (entsel)) (setq ent (entsel))
@@ -303,169 +322,151 @@
;; TEIL 6: BIBLIOTHEK LADEN & MAßE EXTRAHIEREN ;; TEIL 6: BIBLIOTHEK LADEN & MAßE EXTRAHIEREN
;; ============================================================ ;; ============================================================
;; Lädt die Bibliothek und extrahiert ALLE benötigten Maße ;; Laedt alle benoetigten Bloecke aus Einzeldateien und extrahiert KS-Masse.
(defun init-bibliothek ( / temp-obj bogen-winkel) (defun init-bibliothek ( / temp-obj bogen-winkel ks-data ks-ein-pos ks-aus-pos dx dy dz bogen-name)
(dbgf "init-bibliothek") ;; (dbgf "init-bibliothek")
(if *lib-initialized* (if *lib-initialized*
(progn (progn
(princ "\n Bibliothek bereits initialisiert.") (princ "\n Bibliothek bereits initialisiert.")
(dbgreturn t) t
) )
(progn (progn
(setq *ks-cache* nil) (setq *ks-cache* nil)
(princ "\n Lade Blockdefinitionen aus Bibliothek...") (princ "\n Lade Blockdefinitionen aus Einzeldateien...")
(princ (strcat "\n Block-Pfad: " block-pfad))
(if (findfile koordinaten-lib)
;; === AUS_ELEMENT Masse extrahieren ===
(princ "\n Extrahiere AUS_Element Masse...")
(ensure-block-loaded "_3D_AS_90_links")
(if (tblsearch "BLOCK" "_3D_AS_90_links")
(progn (progn
(setq temp-obj (vla-InsertBlock modelspace (setq temp-obj (vla-InsertBlock modelspace
(vlax-3D-point '(0 0 0)) (vlax-3D-point '(0 0 0))
koordinaten-lib "_3D_AS_90_links" 1.0 1.0 1.0 0))
1.0 1.0 1.0 0)) (setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj) (vla-Delete temp-obj)
(princ " OK.") (setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
;; === AUS_ELEMENT Maße extrahieren === (if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(princ "\n Extrahiere AUS_Element Masse...") (if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
(if (tblsearch "BLOCK" "_3D_AS_90_links") )
(if (and ks-ein-pos ks-aus-pos)
(progn (progn
(setq temp-obj (vla-InsertBlock modelspace (setq aus-dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(vlax-3D-point '(0 0 0)) (setq aus-dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
"_3D_AS_90_links" 1.0 1.0 1.0 0)) (setq aus-dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq ks-data (extract-ks-from-block temp-obj)) (princ (strcat "\n AUS_Element: dx=" (rtos aus-dx 2 0) ", dz=" (rtos aus-dz 2 0)))
(vla-Delete temp-obj)
(setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
(if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq aus-dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq aus-dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq aus-dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(princ (strcat "\n AUS_Element: dx=" (rtos aus-dx 2 0) ", dz=" (rtos aus-dz 2 0)))
)
(princ "\n FEHLER: KS_EIN/KS_AUS fehlt im AUS_Element!")
)
) )
(princ "\n FEHLER: Block _3D_AS_90_links nicht gefunden!") (princ "\n FEHLER: KS_EIN/KS_AUS fehlt im AUS_Element!")
) )
)
(princ "\n FEHLER: Block _3D_AS_90_links nicht geladen!")
)
;; === EIN_ELEMENT Maße extrahieren === ;; === EIN_ELEMENT Masse extrahieren ===
(princ "\n Extrahiere EIN_Element Masse...") (princ "\n Extrahiere EIN_Element Masse...")
(if (tblsearch "BLOCK" "_3D_ES_90_links") (ensure-block-loaded "_3D_ES_90_links")
(if (tblsearch "BLOCK" "_3D_ES_90_links")
(progn
(setq temp-obj (vla-InsertBlock modelspace
(vlax-3D-point '(0 0 0))
"_3D_ES_90_links" 1.0 1.0 1.0 0))
(setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj)
(setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
(if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn (progn
(setq temp-obj (vla-InsertBlock modelspace (setq ein-dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(vlax-3D-point '(0 0 0)) (setq ein-dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
"_3D_ES_90_links" 1.0 1.0 1.0 0)) (setq ein-dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq ks-data (extract-ks-from-block temp-obj)) (princ (strcat "\n EIN_Element: dx=" (rtos ein-dx 2 0) ", dz=" (rtos ein-dz 2 0)))
(vla-Delete temp-obj)
(setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
(if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq ein-dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq ein-dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq ein-dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(princ (strcat "\n EIN_Element: dx=" (rtos ein-dx 2 0) ", dz=" (rtos ein-dz 2 0)))
)
(princ "\n FEHLER: KS_EIN/KS_AUS fehlt im EIN_Element!")
)
) )
(princ "\n FEHLER: Block _3D_ES_90_links nicht gefunden!") (princ "\n FEHLER: KS_EIN/KS_AUS fehlt im EIN_Element!")
) )
)
;; === Bogen-Maße extrahieren - ALLE Winkel === (princ "\n FEHLER: Block _3D_ES_90_links nicht geladen!")
(princ "\n Extrahiere Bogen-Maße...") )
(setq bogen-auf '())
(setq bogen-ab '())
;; ALLE verfügbaren Winkel
(setq bogen-winkel '(3 6 9 12 15 18 21 27 33 39 45 51))
(foreach w bogen-winkel
;; Aufwärtsbogen
(setq bogen-name (strcat "Vario_Bogen_auf_" (itoa w) grad-zeichen))
(if (tblsearch "BLOCK" bogen-name)
(progn
(setq temp-obj (vla-InsertBlock modelspace
(vlax-3D-point '(0 0 0))
bogen-name 1.0 1.0 1.0 0))
(setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj)
(foreach item ks-data
(if (= (car item) "KS_EIN")
(setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS")
(setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq bogen-auf (cons (list w dx dy dz) bogen-auf))
(princ (strcat "\n ✓ Bogen_auf_" (itoa w) ": dx=" (rtos dx 2 0) " mm, dz=" (rtos dz 2 0) " mm"))
)
(princ (strcat "\n ✗ Bogen_auf_" (itoa w) ": KS_EIN/KS_AUS fehlt!"))
)
)
(princ (strcat "\n ✗ Bogen_auf_" (itoa w) ": Block nicht gefunden!"))
)
;; Abwärtsbogen
(setq bogen-name (strcat "Vario_Bogen_ab_" (itoa w) grad-zeichen))
(if (tblsearch "BLOCK" bogen-name)
(progn
(setq temp-obj (vla-InsertBlock modelspace
(vlax-3D-point '(0 0 0))
bogen-name 1.0 1.0 1.0 0))
(setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj)
(foreach item ks-data
(if (= (car item) "KS_EIN")
(setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS")
(setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq bogen-ab (cons (list w dx dy dz) bogen-ab))
(princ (strcat "\n ✓ Bogen_ab_" (itoa w) ": dx=" (rtos dx 2 0) " mm, dz=" (rtos dz 2 0) " mm"))
)
(princ (strcat "\n ✗ Bogen_ab_" (itoa w) ": KS_EIN/KS_AUS fehlt!"))
)
)
(princ (strcat "\n ✗ Bogen_ab_" (itoa w) ": Block nicht gefunden!"))
)
)
(setq bogen-auf (reverse bogen-auf))
(setq bogen-ab (reverse bogen-ab))
(setq *lib-initialized* t) ;; === Bogen-Masse extrahieren - ALLE Winkel ===
(princ "\n Bibliothek erfolgreich initialisiert.") (princ "\n Extrahiere Bogen-Masse...")
(dbgreturn t) (setq bogen-auf '())
(setq bogen-ab '())
(setq bogen-winkel '(3 6 9 12 15 18 21 27 33 39 45 51))
(foreach w bogen-winkel
;; Aufwaertsbogen
(setq bogen-name (strcat "Vario_Bogen_auf_" (itoa w) grad-zeichen))
(ensure-block-loaded bogen-name)
(if (tblsearch "BLOCK" bogen-name)
(progn
(setq temp-obj (vla-InsertBlock modelspace (vlax-3D-point '(0 0 0)) bogen-name 1.0 1.0 1.0 0))
(setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj)
(setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
(if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq bogen-auf (cons (list w dx dy dz) bogen-auf))
(princ (strcat "\n OK Bogen_auf_" (itoa w) ": dx=" (rtos dx 2 0) " dz=" (rtos dz 2 0)))
)
(princ (strcat "\n FEHLER Bogen_auf_" (itoa w) ": KS_EIN/KS_AUS fehlt!"))
)
)
(princ (strcat "\n FEHLER Bogen_auf_" (itoa w) ": Block nicht geladen!"))
)
;; Abwaertsbogen
(setq bogen-name (strcat "Vario_Bogen_ab_" (itoa w) grad-zeichen))
(ensure-block-loaded bogen-name)
(if (tblsearch "BLOCK" bogen-name)
(progn
(setq temp-obj (vla-InsertBlock modelspace (vlax-3D-point '(0 0 0)) bogen-name 1.0 1.0 1.0 0))
(setq ks-data (extract-ks-from-block temp-obj))
(vla-Delete temp-obj)
(setq ks-ein-pos nil ks-aus-pos nil)
(foreach item ks-data
(if (= (car item) "KS_EIN") (setq ks-ein-pos (cadr item)))
(if (= (car item) "KS_AUS") (setq ks-aus-pos (cadr item)))
)
(if (and ks-ein-pos ks-aus-pos)
(progn
(setq dx (- (caaddr ks-aus-pos) (caadr ks-ein-pos)))
(setq dy (- (cadr (caddr ks-aus-pos)) (cadr (cadr ks-ein-pos))))
(setq dz (- (caddr (caddr ks-aus-pos)) (caddr (cadr ks-ein-pos))))
(setq bogen-ab (cons (list w dx dy dz) bogen-ab))
(princ (strcat "\n OK Bogen_ab_" (itoa w) ": dx=" (rtos dx 2 0) " dz=" (rtos dz 2 0)))
)
(princ (strcat "\n FEHLER Bogen_ab_" (itoa w) ": KS_EIN/KS_AUS fehlt!"))
)
)
(princ (strcat "\n FEHLER Bogen_ab_" (itoa w) ": Block nicht geladen!"))
) )
) )
(setq bogen-auf (reverse bogen-auf))
(setq bogen-ab (reverse bogen-ab))
(setq *lib-initialized* t)
(princ "\n Bibliothek erfolgreich initialisiert.")
t
) )
) )
) )
;; Bogen-Maß aus Tabelle holen ;; Bogen-Maß aus Tabelle holen
(defun get-bogen-mass (tabelle winkel) (defun get-bogen-mass (tabelle winkel)
(dbgf "get-bogen-mass") ;; (dbgf "get-bogen-mass")
(setq result nil) (setq result nil)
(foreach item tabelle (foreach item tabelle
(if (= (car item) winkel) (if (= (car item) winkel)
@@ -475,26 +476,27 @@
(if (null result) (if (null result)
(princ (strcat "\n FEHLER: Winkel " (itoa winkel) " nicht in Bogen-Tabelle!")) (princ (strcat "\n FEHLER: Winkel " (itoa winkel) " nicht in Bogen-Tabelle!"))
) )
(dbgreturn result) result
) )
;; ============================================================ ;; ============================================================
;; TEIL 7: BLOCK EINFÜGEN MIT KS_EIN AUSRICHTUNG ;; TEIL 7: BLOCK EINFÜGEN MIT KS_EIN AUSRICHTUNG
;; ============================================================ ;; ============================================================
;; Block einfügen OHNE Rotation/Skalierung (für AUS/EIN Elemente) ;; Block einfuegen OHNE Rotation/Skalierung (fuer AUS/EIN Elemente)
(defun insert-block-by-ks (blockname einfuegepunkt / block-obj ks-data ks-ein ks-aus offset ausgang) (defun insert-block-by-ks (blockname einfuegepunkt / block-obj ks-data ks-ein ks-aus offset ausgang)
(if (or (null einfuegepunkt) (not (listp einfuegepunkt))) (if (or (null einfuegepunkt) (not (listp einfuegepunkt)))
(progn (progn
(princ (strcat "\n FEHLER: Ungültiger Einfügepunkt für '" blockname "'")) (princ (strcat "\n FEHLER: Ungueltiger Einfuegepunkt fuer '" blockname "'"))
(exit) (exit)
) )
) )
(if (not *lib-initialized*) (init-bibliothek)) (if (not *lib-initialized*) (init-bibliothek))
(ensure-block-loaded blockname)
(princ (strcat "\n Fuege Block '" blockname "' ein...")) (princ (strcat "\n Fuege Block '" blockname "' ein..."))
(setq block-obj (vla-InsertBlock modelspace (setq block-obj (vla-InsertBlock modelspace
(vlax-3D-point einfuegepunkt) (vlax-3D-point einfuegepunkt)
blockname 1.0 1.0 1.0 0)) blockname 1.0 1.0 1.0 0))
@@ -529,26 +531,27 @@
) )
;; Skalierte und geneigte Staustrecke einfügen (vereinfacht, ohne KS-Extraktion) ;; Skalierte und geneigte Staustrecke einfügen (vereinfacht, ohne KS-Extraktion)
(defun insert-inclined-scaled-block (blockname startpunkt laenge winkel / (defun insert-inclined-scaled-block (blockname startpunkt laenge winkel /
rad matrix block-obj endpunkt scale) rad matrix block-obj endpunkt scale)
(if (<= laenge 0.1) (if (<= laenge 0.1)
(progn (progn
(princ (strcat "\n Laenge=" (rtos laenge 2 2) " mm -> uebersprungen")) (princ (strcat "\n Laenge=" (rtos laenge 2 2) " mm -> uebersprungen"))
startpunkt startpunkt
) )
(progn (progn
(ensure-block-loaded blockname)
(princ (strcat "\n Fuege '" blockname "' ein (Laenge=" (rtos laenge 2 2) " mm, Winkel=" (itoa winkel) "°)")) (princ (strcat "\n Fuege '" blockname "' ein (Laenge=" (rtos laenge 2 2) " mm, Winkel=" (itoa winkel) "°)"))
(setq scale (/ laenge 1000.0)) (setq scale (/ laenge 1000.0))
(setq rad (* winkel (/ pi 180.0))) (setq rad (* winkel (/ pi 180.0)))
;; Block direkt am Startpunkt einfügen (nicht erst bei 0,0,0) ;; Block am Ursprung einfuegen, damit TransformBy um (0,0,0) rotiert (= Block-Einfuegepunkt)
(setq block-obj (vla-InsertBlock modelspace (setq block-obj (vla-InsertBlock modelspace
(vlax-3D-point startpunkt) (vlax-3D-point '(0 0 0))
blockname scale 1.0 1.0 0)) blockname scale 1.0 1.0 0))
;; Rotation um Y-Achse ;; Rotation um Y-Achse (rotiert jetzt korrekt um den Ursprung = Block-Einfuegepunkt)
(setq matrix (list (setq matrix (list
(list (cos rad) 0 (sin rad) 0) (list (cos rad) 0 (sin rad) 0)
(list 0 1 0 0) (list 0 1 0 0)
@@ -556,6 +559,11 @@
(list 0 0 0 1) (list 0 0 0 1)
)) ))
(vla-TransformBy block-obj (vlax-tmatrix matrix)) (vla-TransformBy block-obj (vlax-tmatrix matrix))
;; Danach erst an den Startpunkt verschieben
(vla-Move block-obj
(vlax-3D-point '(0 0 0))
(vlax-3D-point startpunkt))
;; Endpunkt berechnen (für die Verkettung) ;; Endpunkt berechnen (für die Verkettung)
(setq endpunkt (list (+ (car startpunkt) (* laenge (cos rad))) (setq endpunkt (list (+ (car startpunkt) (* laenge (cos rad)))
@@ -568,25 +576,26 @@
) )
) )
;; Fixen Block mit Rotation einfügen (vereinfacht, ohne KS-Extraktion) ;; Fixen Block mit Rotation einfuegen (block-dx/block-dz = Ausdehnung in Block-X/Z)
(defun insert-rotated-block-with-ks (blockname startpunkt winkel / (defun insert-rotated-block-with-ks (blockname startpunkt winkel block-dx block-dz /
rad matrix block-obj endpunkt block-laenge) rad matrix block-obj endpunkt)
(if (or (null startpunkt) (not (listp startpunkt))) (if (or (null startpunkt) (not (listp startpunkt)))
(progn (progn
(princ (strcat "\n FEHLER: Ungültiger Einfügepunkt für '" blockname "'")) (princ (strcat "\n FEHLER: Ungültiger Einfuegepunkt fuer '" blockname "'"))
startpunkt startpunkt
) )
(progn (progn
(ensure-block-loaded blockname)
(princ (strcat "\n Fuege Block '" blockname "' ein (Rotation " (itoa winkel) "°)")) (princ (strcat "\n Fuege Block '" blockname "' ein (Rotation " (itoa winkel) "°)"))
(setq rad (* winkel (/ pi 180.0))) (setq rad (* winkel (/ pi 180.0)))
;; Block direkt am Startpunkt einfügen ;; Block am Ursprung einfuegen, damit TransformBy korrekt um (0,0,0) rotiert
(setq block-obj (vla-InsertBlock modelspace (setq block-obj (vla-InsertBlock modelspace
(vlax-3D-point startpunkt) (vlax-3D-point '(0 0 0))
blockname 1.0 1.0 1.0 0)) blockname 1.0 1.0 1.0 0))
;; Rotation um Y-Achse ;; Rotation um Y-Achse
(setq matrix (list (setq matrix (list
(list (cos rad) 0 (sin rad) 0) (list (cos rad) 0 (sin rad) 0)
@@ -595,21 +604,19 @@
(list 0 0 0 1) (list 0 0 0 1)
)) ))
(vla-TransformBy block-obj (vlax-tmatrix matrix)) (vla-TransformBy block-obj (vlax-tmatrix matrix))
;; Blocklänge für Endpunkt-Berechnung (geschätzt) ;; Danach erst an den Startpunkt verschieben
(setq block-laenge 300) (vla-Move block-obj
(cond (vlax-3D-point '(0 0 0))
((vl-string-search "Umlenk" blockname) (setq block-laenge 500)) (vlax-3D-point startpunkt))
((vl-string-search "Motor" blockname) (setq block-laenge 500))
((vl-string-search "Bogen" blockname) (setq block-laenge 800)) ;; Endpunkt: Rotation des (block-dx, 0, block-dz) Vektors um Y-Achse
(t (setq block-laenge 300)) (setq endpunkt (list
) (+ (car startpunkt) (+ (* block-dx (cos rad)) (* block-dz (sin rad))))
(cadr startpunkt)
(setq endpunkt (list (+ (car startpunkt) (* block-laenge (cos rad))) (+ (caddr startpunkt) (+ (* (- (sin rad)) block-dx) (* (cos rad) block-dz)))))
(cadr startpunkt)
(+ (caddr startpunkt) (* (- (sin rad)) block-laenge)))) (princ (strcat "\n Endpunkt: X=" (rtos (car endpunkt) 2 2) " Z=" (rtos (caddr endpunkt) 2 2)))
(princ (strcat "\n Endpunkt: Z=" (rtos (caddr endpunkt) 2 2)))
endpunkt endpunkt
) )
) )
@@ -621,8 +628,9 @@
winkel-list ergebnis-liste A B cos3 sin3 winkel-list ergebnis-liste A B cos3 sin3
bogen-x1 bogen-z1 bogen-x2 bogen-z2 bogen-x1 bogen-z1 bogen-x2 bogen-z2
abs-dz-AUS abs-dz-EIN L_GF L_VF cosα sinα nenner abs-dz-AUS abs-dz-EIN L_GF L_VF cosα sinα nenner
winkel mass1 mass2 gueltig) winkel mass1 mass2 gueltig
(dbgf "berechne-alle-winkel") best-winkel best-L_GF best-L_VF)
;; (dbgf "berechne-alle-winkel")
;; Bibliothek muss initialisiert sein ;; Bibliothek muss initialisiert sein
(if (not *lib-initialized*) (if (not *lib-initialized*)
@@ -738,13 +746,15 @@
"° (kleinster verfuegbarer Winkel)")) "° (kleinster verfuegbarer Winkel)"))
(princ "\n\n>>> KEIN passender Winkel gefunden!")) (princ "\n\n>>> KEIN passender Winkel gefunden!"))
(dbgreturn (list best-winkel best-L_GF best-L_VF ergebnis-liste)) (list best-winkel best-L_GF best-L_VF ergebnis-liste)
) )
;; ============================================================ ;; ============================================================
;; TEIL 9: MODULE EINFÜGEN (GESAMTE ANLAGE) ;; TEIL 9: MODULE EINFÜGEN (GESAMTE ANLAGE)
;; ============================================================ ;; ============================================================
(defun foerderanlage-einfuegen (deltaL deltaH richtung best-winkel L_GF1 L_GF2 L_VF startpunkt) (defun foerderanlage-einfuegen (deltaL deltaH richtung best-winkel L_GF1 L_GF2 L_VF startpunkt
/ aktueller-punkt bogen-name endpunkt bogen-mass bogen-dx bogen-dz
)
(setq aktueller-punkt startpunkt) (setq aktueller-punkt startpunkt)
(if (not *lib-initialized*) (init-bibliothek)) (if (not *lib-initialized*) (init-bibliothek))
@@ -764,19 +774,26 @@
;; 3. Separator ;; 3. Separator
(princ "\n\n3/11: Separator (300mm, 3° geneigt)") (princ "\n\n3/11: Separator (300mm, 3° geneigt)")
(setq aktueller-punkt (insert-rotated-block-with-ks "Staustrecke_Separator_SP_300_mm" aktueller-punkt 3)) (setq aktueller-punkt (insert-rotated-block-with-ks "Staustrecke_Separator_SP_300_mm" aktueller-punkt 3 300 0))
;; 4. Umlenkstation ;; 4. Umlenkstation Block bereits 3° vorgeneigt, keine zusaetzliche Rotation
(princ "\n\n4/11: Umlenkstation (500mm, 3° geneigt)") (princ "\n\n4/11: Umlenkstation (500mm, 3° geneigt)")
(setq aktueller-punkt (insert-rotated-block-with-ks "Vario_Umlenkstation_500mm" aktueller-punkt 3)) (setq aktueller-punkt (insert-rotated-block-with-ks "Vario_Umlenkstation_500mm" aktueller-punkt 0 499 -26))
;; 5. 1. Vertikalbogen ;; 5. 1. Vertikalbogen
(if (= richtung "Auf") (if (= richtung "Auf")
(setq bogen-name (strcat "Vario_Bogen_auf_" (itoa best-winkel) grad-zeichen)) (progn
(setq bogen-name (strcat "Vario_Bogen_ab_" (itoa best-winkel) grad-zeichen)) (setq bogen-name (strcat "Vario_Bogen_auf_" (itoa best-winkel) grad-zeichen))
(setq bogen-mass (get-bogen-mass bogen-auf best-winkel))
)
(progn
(setq bogen-name (strcat "Vario_Bogen_ab_" (itoa best-winkel) grad-zeichen))
(setq bogen-mass (get-bogen-mass bogen-ab best-winkel))
)
) )
(setq bogen-dx (car bogen-mass) bogen-dz (caddr bogen-mass))
(princ (strcat "\n\n5/11: " bogen-name " (3° geneigt)")) (princ (strcat "\n\n5/11: " bogen-name " (3° geneigt)"))
(setq aktueller-punkt (insert-rotated-block-with-ks bogen-name aktueller-punkt 3)) (setq aktueller-punkt (insert-rotated-block-with-ks bogen-name aktueller-punkt 3 bogen-dx bogen-dz))
;; 6. Variable Strecke L_VF ;; 6. Variable Strecke L_VF
(if (> L_VF 0.1) (if (> L_VF 0.1)
@@ -797,16 +814,23 @@
;; 7. 2. Vertikalbogen ;; 7. 2. Vertikalbogen
(if (= richtung "Auf") (if (= richtung "Auf")
(setq bogen-name (strcat "Vario_Bogen_ab_" (itoa best-winkel) grad-zeichen)) (progn
(setq bogen-name (strcat "Vario_Bogen_auf_" (itoa best-winkel) grad-zeichen)) (setq bogen-name (strcat "Vario_Bogen_ab_" (itoa best-winkel) grad-zeichen))
(setq bogen-mass (get-bogen-mass bogen-ab best-winkel))
)
(progn
(setq bogen-name (strcat "Vario_Bogen_auf_" (itoa best-winkel) grad-zeichen))
(setq bogen-mass (get-bogen-mass bogen-auf best-winkel))
)
) )
(princ (strcat "\n\n7/11: " bogen-name " (3° geneigt)")) (setq bogen-dx (car bogen-mass) bogen-dz (caddr bogen-mass))
(setq aktueller-punkt (insert-rotated-block-with-ks bogen-name aktueller-punkt (- best-winkel))) (princ (strcat "\n\n7/11: " bogen-name " (" (itoa (- best-winkel)) "° geneigt)"))
(setq aktueller-punkt (insert-rotated-block-with-ks bogen-name aktueller-punkt (- best-winkel) bogen-dx bogen-dz))
;; 8. Motorstation
;; 8. Motorstation gleiche Behandlung wie Umlenkstation
(princ "\n\n8/11: Motorstation (500mm, 3° geneigt)") (princ "\n\n8/11: Motorstation (500mm, 3° geneigt)")
(setq aktueller-punkt (insert-rotated-block-with-ks "Vario_Motorstation_500mm" aktueller-punkt 3)) (setq aktueller-punkt (insert-rotated-block-with-ks "Vario_Motorstation_500mm" aktueller-punkt 0 499 -26))
;; 9. 2. Gefällestrecke ;; 9. 2. Gefällestrecke
(if (> L_GF2 0.1) (if (> L_GF2 0.1)
(progn (progn
@@ -818,7 +842,7 @@
;; 10. Separator 2 ;; 10. Separator 2
(princ "\n\n10/11: Separator (300mm, 3° geneigt)") (princ "\n\n10/11: Separator (300mm, 3° geneigt)")
(setq aktueller-punkt (insert-rotated-block-with-ks "Staustrecke_Separator_SP_300_mm" aktueller-punkt 3)) (setq aktueller-punkt (insert-rotated-block-with-ks "Staustrecke_Separator_SP_300_mm" aktueller-punkt 3 300 0))
;; 11. EIN_Element ;; 11. EIN_Element
(princ "\n\n11/11: _3D_ES_90_links (0°)") (princ "\n\n11/11: _3D_ES_90_links (0°)")
@@ -836,8 +860,9 @@
(defun c:FOERDERANLAGE ( / eingabe-modus line-points startpunkt endpunkt differenz (defun c:FOERDERANLAGE ( / eingabe-modus line-points startpunkt endpunkt differenz
deltaL deltaH deltaX deltaY richtung ergebnis deltaL deltaH deltaX deltaY richtung ergebnis
best-winkel L_GF L_GF1 L_GF2 L_VF ergebnis-liste best-winkel L_GF L_GF1 L_GF2 L_VF ergebnis-liste
antwort verteilung-modus) antwort verteilung-modus
(dbgf "c:FOERDERANLAGE") gueltige-winkel idx eintrag wahl)
;; (dbgf "c:FOERDERANLAGE")
(princ "\n=========================================") (princ "\n=========================================")
(princ "\n FÖRDERANLAGE GENERATOR v25.0") (princ "\n FÖRDERANLAGE GENERATOR v25.0")
@@ -927,19 +952,56 @@
;; Berechnung ;; Berechnung
(setq ergebnis (berechne-alle-winkel deltaL deltaH richtung)) (setq ergebnis (berechne-alle-winkel deltaL deltaH richtung))
(setq best-winkel (car ergebnis) L_GF (cadr ergebnis) L_VF (caddr ergebnis)) (setq ergebnis-liste (cadddr ergebnis))
(if (or (null best-winkel) (null L_GF) (null L_VF) (<= L_GF 0) (<= L_VF 0)) ;; Gueltige Winkel ermitteln
(progn (setq gueltige-winkel
(mapcar 'car
(vl-remove-if-not
(function (lambda (e) (and (nth 3 e)
(numberp (nth 1 e)) (numberp (nth 2 e))
(>= (nth 1 e) 0) (>= (nth 2 e) 0))))
ergebnis-liste)))
(if (null gueltige-winkel)
(progn
(alert (strcat "Kein passender Winkel gefunden!\n\n" (alert (strcat "Kein passender Winkel gefunden!\n\n"
"ΔL=" (rtos deltaL 2 0) " mm, ΔH=" (rtos deltaH 2 0) " mm, Richtung=" richtung "DeltaL=" (rtos deltaL 2 0) " mm, DeltaH=" (rtos deltaH 2 0)
"\nBitte andere Werte versuchen.")) " mm, Richtung=" richtung "\nBitte andere Werte versuchen."))
(exit) (exit)
) )
) )
;; Winkelauswahl: bei einem Winkel automatisch, bei mehreren Dialog
(if (= (length gueltige-winkel) 1)
(progn
(setq best-winkel (car gueltige-winkel))
(setq eintrag (assoc best-winkel ergebnis-liste))
(setq L_GF (nth 1 eintrag) L_VF (nth 2 eintrag))
(princ (strcat "\n\n>>> Nur ein gueltiger Winkel: " (itoa best-winkel) grad-zeichen))
)
(progn
(princ "\n\nMehrere gueltige Winkel verfuegbar. Bitte waehlen:")
(setq idx 1)
(foreach w gueltige-winkel
(setq eintrag (assoc w ergebnis-liste))
(princ (strcat "\n " (itoa idx) " - " (itoa w) grad-zeichen
" (L_GF=" (rtos (nth 1 eintrag) 2 1)
" mm, L_VF=" (rtos (nth 2 eintrag) 2 1) " mm)"))
(setq idx (1+ idx))
)
(setq wahl (getint (strcat "Winkel waehlen (1-"
(itoa (length gueltige-winkel)) ") [1]: ")))
(if (or (null wahl) (< wahl 1) (> wahl (length gueltige-winkel)))
(setq wahl 1))
(setq best-winkel (nth (1- wahl) gueltige-winkel))
(setq eintrag (assoc best-winkel ergebnis-liste))
(setq L_GF (nth 1 eintrag) L_VF (nth 2 eintrag))
)
)
(princ "\n\n=========================================") (princ "\n\n=========================================")
(princ (strcat "\n>>> Empfohlener Winkel: " (itoa best-winkel) "°")) (princ (strcat "\n>>> Gewaehlter Winkel: " (itoa best-winkel) grad-zeichen))
(princ (strcat "\n>>> L_GF (gesamt): " (rtos L_GF 2 2) " mm")) (princ (strcat "\n>>> L_GF (gesamt): " (rtos L_GF 2 2) " mm"))
(princ (strcat "\n>>> L_VF: " (rtos L_VF 2 2) " mm")) (princ (strcat "\n>>> L_VF: " (rtos L_VF 2 2) " mm"))
(princ "\n=========================================") (princ "\n=========================================")
@@ -985,7 +1047,7 @@
(princ "\nVorgang abgebrochen.") (princ "\nVorgang abgebrochen.")
) )
(dbgreturn nil) nil
) )
;; ============================================================ ;; ============================================================
;; START ;; START
+1 -1
View File
@@ -21,7 +21,7 @@ set "DXFM_TESTOUT=%DXFM_TESTS%\output"
set "DXFM_TESTREF=%DXFM_TESTS%\reference" set "DXFM_TESTREF=%DXFM_TESTS%\reference"
set "DXFM_CFG=%DXFMAKRO%\cfg" set "DXFM_CFG=%DXFMAKRO%\cfg"
set "DXFM_LOG=%DXFMAKRO%\logs" set "DXFM_LOG=%DXFMAKRO%\logs"
set "DXFM_BLOCKS=%DXFMAKRO%\Blocks" set "DXFM_BLOCKS=%DXFMAKRO%\data\ils"
set "DXFM_LISP=%DXFMAKRO%\Lisp" set "DXFM_LISP=%DXFMAKRO%\Lisp"
set "DXFM_DCL=%DXFMAKRO%\dcl" set "DXFM_DCL=%DXFMAKRO%\dcl"
set "DXFM_RESULTS=%DXFMAKRO%\results" set "DXFM_RESULTS=%DXFMAKRO%\results"
Binary file not shown.
Binary file not shown.
View File
+4020
View File
File diff suppressed because it is too large Load Diff
+4020
View File
File diff suppressed because it is too large Load Diff
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -45,7 +45,7 @@ def get_block_path():
"""Block-Pfad aus Umgebungsvariable DXFM_BLOCKS lesen.""" """Block-Pfad aus Umgebungsvariable DXFM_BLOCKS lesen."""
bp = os.environ.get("DXFM_BLOCKS", "") bp = os.environ.get("DXFM_BLOCKS", "")
if not bp: if not bp:
bp = "C:/Users/y.wang/Documents/dxfmakros/Blocks/" bp = "C:/Users/y.wang/Documents/dxfmakros/data/ils/"
print(f"\nUmgebungsvariable DXFM_BLOCKS nicht gefunden. Nutze Standardpfad: {bp}") print(f"\nUmgebungsvariable DXFM_BLOCKS nicht gefunden. Nutze Standardpfad: {bp}")
bp = bp.replace("\\", "/").rstrip("/") + "/" bp = bp.replace("\\", "/").rstrip("/") + "/"
return bp return bp
+145
View File
@@ -0,0 +1,145 @@
"""
Teilt ils_library.dxf in einzelne DXF-Dateien pro Block auf.
Jede Ausgabedatei enthaelt den Block + alle seine Unterblock-Abhaengigkeiten.
Aufruf: python split_block_library.py
"""
import os
import sys
import ezdxf
from ezdxf.document import Drawing
# Pfade
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.dirname(SCRIPT_DIR)
LIB_PATH = os.path.join(PROJECT_ROOT, "data", "block_libraries", "ils_library.dxf")
OUT_DIR = os.path.join(PROJECT_ROOT, "data", "ils")
# Nur diese Bloecke exportieren (alle fuer den Vario-Foerderer relevanten)
EXPORT_PREFIXES = (
"Vario_",
"Staustrecke_",
"_3D_AS_",
"_3D_ES_",
)
# Abhaengigkeiten: KS_EIN und KS_AUS muessen immer mitgeliefert werden
ALWAYS_INCLUDE = {"KS_EIN", "KS_AUS"}
def collect_dependencies(src_doc: Drawing, blockname: str, visited: set) -> set:
"""Gibt alle Unterblock-Namen zurueck, die 'blockname' direkt oder transitiv benoetigt."""
if blockname in visited:
return visited
visited.add(blockname)
if blockname not in src_doc.blocks:
return visited
blk = src_doc.blocks[blockname]
for entity in blk:
if entity.dxftype() == "INSERT":
ref = entity.dxf.name
collect_dependencies(src_doc, ref, visited)
return visited
def copy_block(src_doc: Drawing, dst_doc: Drawing, blockname: str):
"""Kopiert einen Block und seine Abhaengigkeiten von src nach dst."""
deps = collect_dependencies(src_doc, blockname, set())
for name in deps:
if name not in src_doc.blocks:
continue
if name in dst_doc.blocks:
continue
src_blk = src_doc.blocks[name]
# Neuen Block im Zieldokument anlegen
dst_blk = dst_doc.blocks.new(
name=name,
base_point=src_blk.block.dxf.base_point if hasattr(src_blk.block.dxf, "base_point") else (0, 0, 0),
)
# Alle Entities kopieren (ausser BLOCK/ENDBLK - die werden automatisch erstellt)
for entity in src_blk:
try:
dst_blk.add_entity(entity.copy())
except Exception:
pass
def export_block(src_doc: Drawing, blockname: str, out_dir: str):
"""Exportiert einen einzelnen Block als eigene DXF-Datei."""
safe_name = blockname.replace("/", "_").replace("\\", "_")
out_path = os.path.join(out_dir, safe_name + ".dxf")
dst_doc = ezdxf.new(dxfversion="R2010")
dst_doc.units = src_doc.units
# Layer aus Quelldatei uebernehmen (nur die benutzten)
for layer in src_doc.layers:
if layer.dxf.name not in dst_doc.layers:
try:
dst_doc.layers.new(
name=layer.dxf.name,
dxfattribs={"color": layer.dxf.get("color", 7)},
)
except Exception:
pass
# Block + Abhaengigkeiten kopieren
copy_block(src_doc, dst_doc, blockname)
dst_doc.saveas(out_path)
return out_path
def main():
print(f"Lese Bibliothek: {LIB_PATH}")
if not os.path.exists(LIB_PATH):
print(f"FEHLER: Datei nicht gefunden: {LIB_PATH}")
sys.exit(1)
src_doc = ezdxf.readfile(LIB_PATH)
print(f" Geladen. Bloecke gesamt: {len(list(src_doc.blocks))}")
os.makedirs(OUT_DIR, exist_ok=True)
# Relevante Bloecke filtern
to_export = []
for blk in src_doc.blocks:
name = blk.name
if name.startswith("*"):
continue
if any(name.startswith(p) for p in EXPORT_PREFIXES) or name in ALWAYS_INCLUDE:
to_export.append(name)
print(f" Zu exportierende Bloecke: {len(to_export)}")
ok = 0
fail = 0
for name in sorted(to_export):
try:
out = export_block(src_doc, name, OUT_DIR)
# KS_EIN/KS_AUS pruefen
check_doc = ezdxf.readfile(out)
has_ks_ein = "KS_EIN" in check_doc.blocks
has_ks_aus = "KS_AUS" in check_doc.blocks
ks_status = ""
if name not in ALWAYS_INCLUDE:
blk = check_doc.blocks[name]
inserts = [e.dxf.name for e in blk if e.dxftype() == "INSERT"]
has_ks_ein_ref = "KS_EIN" in inserts
has_ks_aus_ref = "KS_AUS" in inserts
ks_status = f" KS_EIN={'ja' if has_ks_ein_ref else 'NEIN'} KS_AUS={'ja' if has_ks_aus_ref else 'NEIN'}"
print(f" OK {name}{ks_status}")
ok += 1
except Exception as e:
print(f" FEHLER {name}: {e}")
fail += 1
print(f"\nErgebnis: {ok} exportiert, {fail} Fehler")
print(f"Ausgabeverzeichnis: {OUT_DIR}")
if __name__ == "__main__":
main()