diff --git a/Lisp/VarioFoerderer.lsp b/Lisp/VarioFoerderer.lsp index 57e8ebe..737a993 100644 --- a/Lisp/VarioFoerderer.lsp +++ b/Lisp/VarioFoerderer.lsp @@ -9,7 +9,13 @@ ;; ============================================================ ;; TEIL 1: GLOBALE EINSTELLUNGEN ;; ============================================================ -(setq modul-pfad (strcat (getenv "DXFM_BLOCKS") "/")) +(if (getenv "DXFM_BLOCKS") + (setq modul-pfad (strcat (getenv "DXFM_BLOCKS") "/")) + (progn + (alert "Umgebungsvariable DXFM_BLOCKS nicht gesetzt! Verwende Standardpfad.") + (setq modul-pfad "c:/10-Develop/gitrepos/dxfmakros/Blocks/") + ) +) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq modelspace (vla-get-ModelSpace doc)) @@ -31,27 +37,104 @@ (setq FESTE_HORIZONTAL 1600) ;; ============================================================ -;; TEIL 3: BOGEN-MASSE (für X-Werte aus Tabelle) +;; KONFIGURATION: Flag für dynamische BoundingBox-Berechnung +;; Setze auf t für dynamische Berechnung aus .dwg-Dateien +;; Setze auf nil für feste, hartkodierte Werte ;; ============================================================ -(setq bogen-auf-unten +(setq use-dynamic-bbox t) ;; Ändere hier: t = dynamisch, nil = hartkodiert + +;; ============================================================ +;; Feste, hartkodierte Bogen-Tabellen (Fallback) +;; ============================================================ +(setq bogen-auf-unten-hardcoded '((3 399.73 0 0)(9 297.95 0 15.61)(12 296.52 0 23.34) (15 593.04 0 62.33)(24 583.13 0 100.09)(36 847.53 0 234.76) (48 1063.24 0 448.91)) ) -(setq bogen-auf-oben +(setq bogen-auf-oben-hardcoded '((3 391.46 0 0)(9 281.45 0 14.75)(12 275.96 0 21.72) (15 568.46 0 59.75)(24 546.87 0 93.37)(36 796.96 0 219.78) (48 1000.4 0 422.88)) ) -(setq bogen-ab-oben +(setq bogen-ab-oben-hardcoded '((9 389.31 0 -40.92)(12 284.23 0 -37.42)(15 389.31 0 -40.92) (24 552.27 0 -124.51)(36 796.35 0 -265.43)(48 732.51 0 -349.39)) ) -(setq bogen-ab-unten +(setq bogen-ab-unten-hardcoded '((9 397.54 0 -41.78)(12 296.52 0 -39.04)(15 493.38 0 -70.19) (24 580.27 0 -131.23)(36 838.65 0 -280.41)(48 787.08 0 -375.42)) ) +;; ============================================================ +;; Funktion zum Berechnen der BoundingBox eines Blocks (temporäres Einfügen) +;; ============================================================ +(defun get-block-bbox (blockname / obj minpt maxpt dx dz) + (if (findfile blockname) + (progn + ;; Temporär einfügen bei (0,0,0) + (setq obj (vla-InsertBlock modelspace (vlax-3D-point '(0 0 0)) blockname 1.0 1.0 1.0 0)) + ;; BoundingBox abfragen + (vla-GetBoundingBox obj 'minpt 'maxpt) + (setq minpt (vlax-safearray->list minpt)) + (setq maxpt (vlax-safearray->list maxpt)) + ;; Differenzen berechnen + (setq dx (- (car maxpt) (car minpt))) ;; X-Ausdehnung + (setq dz (- (caddr maxpt) (caddr minpt))) ;; Z-Ausdehnung + ;; Objekt löschen + (vla-Delete obj) + ;; Rückgabe: (dx 0 dz) + (list dx 0 dz) + ) + (progn + (princ (strcat "\nFEHLER: Blockdatei nicht gefunden: " blockname)) + '(0 0 0) ;; Fallback + ) + ) +) + +;; ============================================================ +;; Funktion zum Erstellen der Bogen-Tabellen dynamisch +;; ============================================================ +(defun create-bogen-table (richtung unten-oben / winkel-list table bbox) + (setq winkel-list '(3 9 12 15 24 36 48)) + (setq table '()) + (foreach winkel winkel-list + (setq blockname (strcat modul-pfad "Vertikalbogen_" richtung "_" (itoa winkel) "_" unten-oben ".dwg")) + (setq bbox (get-block-bbox blockname)) + (if (and (> (car bbox) 0) (> (caddr bbox) 0)) ;; Nur gültige Werte + (setq table (cons (cons winkel bbox) table)) + (princ (strcat "\nWARNUNG: Ungültige BoundingBox für " blockname)) + ) + ) + (reverse table) +) + +;; ============================================================ +;; TEIL 3: BOGEN-MASSE (Verzweigung basierend auf Flag) +;; ============================================================ +(if use-dynamic-bbox + (progn + (princ "\nVerwende dynamische BoundingBox-Berechnung für Bogen-Tabellen...") + (if (null bogen-auf-unten) + (progn + (setq bogen-auf-unten (create-bogen-table "Auf" "Unten")) + (setq bogen-auf-oben (create-bogen-table "Auf" "Oben")) + (setq bogen-ab-oben (create-bogen-table "Ab" "Oben")) + (setq bogen-ab-unten (create-bogen-table "Ab" "Unten")) + (princ "\nDynamische Bogen-Tabellen initialisiert.") + ) + ) + ) + (progn + (princ "\nVerwende hartkodierte Werte für Bogen-Tabellen...") + (setq bogen-auf-unten bogen-auf-unten-hardcoded) + (setq bogen-auf-oben bogen-auf-oben-hardcoded) + (setq bogen-ab-oben bogen-ab-oben-hardcoded) + (setq bogen-ab-unten bogen-ab-unten-hardcoded) + (princ "\nHartkodierte Bogen-Tabellen geladen.") + ) +) + ;; ============================================================ ;; TEIL 4: HILFSFUNKTIONEN ;; ============================================================ @@ -104,16 +187,16 @@ ;; ============================================================ ;; 🔥 METHODE 2: Für nicht-rotierte Blöcke (AUS_Element, EIN_Element) -;; X und Z aus BoundingBox (komplett aus Block-Geometrie) +;; X und Z aus BoundingBox (relativ zum Startpunkt) ;; ============================================================ (defun get-block-endpoint-nonrotated (obj startpunkt) (vla-GetBoundingBox obj 'minpt 'maxpt) (setq minpt (vlax-safearray->list minpt)) (setq maxpt (vlax-safearray->list maxpt)) - (list (car maxpt) ;; X aus BBox - (cadr startpunkt) ;; Y gleich - (caddr maxpt)) ;; Z aus BBox + (list (+ (car startpunkt) (- (car maxpt) (car minpt))) ;; Relative DX + (cadr startpunkt) ;; Y unverändert + (+ (caddr startpunkt) (- (caddr maxpt) (caddr minpt)))) ;; Relative DZ ) ;; ============================================================ @@ -442,15 +525,19 @@ ) ;; ========================================================== - ;; 11. EIN_Element_links (METHODE 2: nicht rotiert, X und Z aus BoundingBox) + ;; 11. EIN_Element_links (feste Werte wie AUS_Element) ;; ========================================================== (princ "\n11/11: EIN_Element_links") (setq blockname (strcat modul-pfad "EIN_Element_links.dwg")) (if (findfile blockname) (progn (setq block (InsertBlock blockname aktueller-punkt 1.0)) - (setq aktueller-punkt (get-block-endpoint-nonrotated block aktueller-punkt)) - (princ (strcat "\n → EIN_Element Ausgang: X=" (rtos (car aktueller-punkt) 2 2) + ;; Verwenden Sie die manuellen Werte statt BoundingBox + (setq aktueller-punkt (list + (+ (car aktueller-punkt) ein-dx) + (+ (cadr aktueller-punkt) ein-dy) + (+ (caddr aktueller-punkt) ein-dz))) + (princ (strcat "\n → EIN_Element Ausgang (manuell): X=" (rtos (car aktueller-punkt) 2 2) ", Y=" (rtos (cadr aktueller-punkt) 2 2) ", Z=" (rtos (caddr aktueller-punkt) 2 2))) )