From f05340ed59ee6265ff9e0b7b9bd3ef63ac19c5fb Mon Sep 17 00:00:00 2001 From: Michael Stangl Date: Wed, 10 Jun 2026 17:22:02 +0200 Subject: [PATCH] Omniflo Export funktion geschrieben --- Lisp/tests.lsp | 264 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 1 deletion(-) diff --git a/Lisp/tests.lsp b/Lisp/tests.lsp index f477324..8fce396 100644 --- a/Lisp/tests.lsp +++ b/Lisp/tests.lsp @@ -112,7 +112,7 @@ (setq ed (entget ename)) (setq bname (cdr (assoc 2 ed))) (if (or - (wcmatch bname "KR_*") + (wcmatch bname "KR_*,KREISEL_*,ECKRAD_*") (wcmatch (strcase bname) "AP110*,AP_110*") (wcmatch bname "Vario*,Staustrecke*,AUS_Element*,EIN_Element*") ;; Rein numerische Namen = Omniflo SivasNr (Boegen/Weichen) @@ -203,6 +203,268 @@ (csv:run-export "EXPORTCSV" "export_csv.py" "export.csv") ) +;; ============================================================ +;; Omniflo-Elemente zaehlen und CSV-Export (rein LISP, ohne Python) +;; +;; Erkennt Omniflo Bloecke anhand Attribute: +;; TEILEART = "Omniflo Kurve" -> Bogen +;; TEILEART = "Omniflo Weiche" -> Weiche +;; Blockname AP110* -> Gerade +;; ============================================================ + +;; --- Attribut-Wert eines INSERT-Blocks nach Tag lesen --- +(defun csv:get-attrib (ename tag / obj ed typ atag) + (setq obj (entnext ename)) + (while obj + (setq ed (entget obj)) + (setq typ (cdr (assoc 0 ed))) + (if (equal typ "SEQEND") + (setq obj nil) + (progn + (if (and (equal typ "ATTRIB") + (= (strcase (cdr (assoc 2 ed))) (strcase tag))) + (progn (setq obj nil) (setq atag (cdr (assoc 1 ed)))) + (setq obj (entnext obj)) + ) + ) + ) + ) + atag +) + +;; --- Omniflo-Block klassifizieren --- +;; Gibt "bogen", "weiche", "gerade" oder nil zurueck +(defun csv:omni-classify (ename bname / teileart) + (setq teileart (csv:get-attrib ename "TEILEART")) + (cond + ((and teileart (= teileart "Omniflo Kurve")) "bogen") + ((and teileart (= teileart "Omniflo Weiche")) "weiche") + ((wcmatch (strcase bname) "AP110*,AP_110*") "gerade") + (t nil) + ) +) + +;; --- Weichen-Subtyp fuer Omniflo Sum Zaehlung bestimmen --- +;; Gibt "einzelweiche", "doppelweiche", "dreiwegeweiche", +;; "deltaweiche", "sternweiche" oder "weichenkoerper" zurueck +(defun csv:omni-weichensubtyp (ename / wtyp beschr) + (setq wtyp (csv:get-attrib ename "WEICHENTYP")) + (setq beschr (csv:get-attrib ename "BESCHR")) + (if (null wtyp) (setq wtyp "")) + (if (null beschr) (setq beschr "")) + (cond + ((vl-string-search "WEICHENK" (strcase beschr)) "weichenkoerper") + ((= wtyp "Einzelweiche") "einzelweiche") + ((= wtyp "Doppelweiche") "doppelweiche") + ((= wtyp "Dreiwegeweiche") "dreiwegeweiche") + ((= wtyp "Deltaweiche") "deltaweiche") + ((= wtyp "Dreifachweiche") "deltaweiche") + ((= wtyp "Sternweiche") "sternweiche") + ((vl-string-search "DELTA" (strcase beschr)) "deltaweiche") + ((vl-string-search "STAR" (strcase beschr)) "sternweiche") + (t "einzelweiche") + ) +) + +;; --- Merkmale-JSON fuer einen Bogen bauen --- +(defun csv:omni-bogen-merkmale (ename rotation / winkel radius sivasnr) + (setq winkel (if (csv:get-attrib ename "WINKEL") (csv:get-attrib ename "WINKEL") "0")) + (setq radius (if (csv:get-attrib ename "RADIUS") (csv:get-attrib ename "RADIUS") "0")) + (setq sivasnr (if (csv:get-attrib ename "ARTINR") (csv:get-attrib ename "ARTINR") "")) + (strcat "{\"L\\u00e4nge in Meter\":\"0\"" + ",\"Kurvenwinkel\":" winkel + ",\"Radius\":" radius + ",\"H\\u00f6he\":\"2000\"" + ",\"Drehung\":" (rtos rotation 2 1) + ",\"SivasNummer\":\"" (csv:json-escape sivasnr) "\"}") +) + +;; --- Merkmale-JSON fuer eine Weiche bauen --- +(defun csv:omni-weiche-merkmale (ename rotation / wtyp winkel sivasnr tef-str) + (setq wtyp (if (csv:get-attrib ename "WEICHENTYP") (csv:get-attrib ename "WEICHENTYP") "Einzelweiche")) + (setq winkel (if (csv:get-attrib ename "WINKEL") (csv:get-attrib ename "WINKEL") "0")) + (setq sivasnr (if (csv:get-attrib ename "ARTINR") (csv:get-attrib ename "ARTINR") "")) + (setq tef-str (csv:get-attrib ename "SIVASNR_TEF")) + (strcat "{\"L\\u00e4nge in Meter links\":null" + ",\"L\\u00e4nge in Meter rechts\":null" + ",\"L\\u00e4nge in Meter gerade\":null" + ",\"Weichentyp\":\"" (csv:json-escape wtyp) "\"" + ",\"Richtung\":\"False\"" + ",\"Weichenwinkel\":" winkel + ",\"H\\u00f6he\":\"2000\"" + ",\"Drehung\":" (rtos rotation 2 1) + ",\"Antrieb Kurve\":" (if (and tef-str (> (strlen tef-str) 0)) "true" "false") + ",\"SivasNummer\":\"" (csv:json-escape sivasnr) "\"}") +) + +;; --- Merkmale-JSON fuer eine Gerade bauen --- +(defun csv:omni-gerade-merkmale (ename rotation / laenge) + (setq laenge (csv:get-attrib ename "LAENGE")) + (if (null laenge) (setq laenge (csv:get-attrib ename "A"))) + (if (null laenge) (setq laenge "2000")) + (strcat "{\"Anzahl der Separatoren\":\"0\"" + ",\"L\\u00e4nge in Meter\":\"" (csv:json-escape (rtos (/ (atof laenge) 1000.0) 2 2)) "\"" + ",\"Winkel\":\"0\"" + ",\"Anzahl der Scanner\":0" + ",\"H\\u00f6he oben\":\"2000\"" + ",\"H\\u00f6he unten\":\"2000\"" + ",\"Drehung\":" (rtos rotation 2 1) + ",\"SivasNummer\":\"\"}") +) + +;; --- Omniflo Sum Zeile bauen --- +(defun csv:omni-sum-zeile (elem-nr cnt-boegen cnt-wk cnt-einzel cnt-delta cnt-doppel cnt-stern len-ap110 len-ap60) + (strcat (itoa elem-nr) + ";\"Omniflo Sum\";\"autogenerated_of_json\";\"Omniflo sum\";1;" + "{\"Anzahl B\\u00f6gen\":" (itoa cnt-boegen) + ",\"Anzahl Weichengrundk\\u00f6rper\":" (itoa cnt-wk) + ",\"Anzahl Einwegweichen\":" (itoa cnt-einzel) + ",\"Anzahl Deltaweichen\":" (itoa cnt-delta) + ",\"Anzahl Doppelweichen und Dreiwegeweichen\":" (itoa cnt-doppel) + ",\"Anzahl Sternweichen\":" (itoa cnt-stern) + ",\"Gesamtl\\u00e4nge AP110\":" (rtos len-ap110 2 1) + ",\"Gesamtl\\u00e4nge AP60\":" (rtos len-ap60 2 1) + "}") +) + +;; --- CSV-Zeile fuer ein Omniflo-Element bauen --- +(defun csv:omni-csv-line (elem-nr teileart bezeichnung merkmale-json) + (strcat (itoa elem-nr) + ";\"" teileart "\"" + ";\"shape_" (substr (rtos (* (getvar "CDATE") 1000000.0) 2 0) 1 8) + (substr (rtos (* (getvar "TDUSRTIMER") 1000000.0) 2 0) 1 8) "\"" + ";\"" bezeichnung "\"" + ";1" + ";" merkmale-json) +) + +;; ============================================================ +;; C:OMNI_EXPORT - Omniflo-Elemente zaehlen und als CSV exportieren +;; Rein LISP-basiert, kein Python noetig. +;; ============================================================ +(defun c:OMNI_EXPORT ( / ss-all i ename ed bname rotation typ + elem-nr cnt-boegen cnt-weichen cnt-geraden + cnt-wk cnt-einzel cnt-delta cnt-doppel cnt-stern + len-ap110 len-ap60 laenge-str + fh out-pfad lines subtyp merkmale) + + (princ "\n[OMNI_EXPORT] Sammle Omniflo-Elemente...") + (setq ss-all (ssget "X" (list (cons 0 "INSERT")))) + (if (null ss-all) + (progn (princ "\n[OMNI_EXPORT] Keine INSERT-Bloecke in der Zeichnung.") (princ)) + (progn + ;; Zaehler initialisieren + (setq elem-nr 0) + (setq cnt-boegen 0 cnt-weichen 0 cnt-geraden 0) + (setq cnt-wk 0 cnt-einzel 0 cnt-delta 0 cnt-doppel 0 cnt-stern 0) + (setq len-ap110 0.0 len-ap60 0.0) + (setq lines '()) + + ;; Alle INSERT-Entities durchgehen + (setq i 0) + (while (setq ename (ssname ss-all i)) + (setq ed (entget ename)) + (setq bname (cdr (assoc 2 ed))) + (setq rotation (cdr (assoc 50 ed))) + (if (null rotation) (setq rotation 0.0)) + (setq rotation (* (/ rotation pi) 180.0)) + + (setq typ (csv:omni-classify ename bname)) + + (cond + ;; --- Bogen --- + ((= typ "bogen") + (setq elem-nr (1+ elem-nr)) + (setq cnt-boegen (1+ cnt-boegen)) + (setq merkmale (csv:omni-bogen-merkmale ename rotation)) + (setq lines (cons + (csv:omni-csv-line elem-nr "Omniflo Kurve" + (strcat "OFBogen :" (itoa cnt-boegen)) merkmale) + lines)) + ) + + ;; --- Weiche --- + ((= typ "weiche") + (setq elem-nr (1+ elem-nr)) + (setq cnt-weichen (1+ cnt-weichen)) + (setq subtyp (csv:omni-weichensubtyp ename)) + (cond + ((= subtyp "weichenkoerper") (setq cnt-wk (1+ cnt-wk))) + ((= subtyp "einzelweiche") (setq cnt-einzel (1+ cnt-einzel))) + ((= subtyp "deltaweiche") (setq cnt-delta (1+ cnt-delta))) + ((= subtyp "sternweiche") (setq cnt-stern (1+ cnt-stern))) + (t (setq cnt-doppel (1+ cnt-doppel))) + ) + (setq merkmale (csv:omni-weiche-merkmale ename rotation)) + (setq lines (cons + (csv:omni-csv-line elem-nr "Omniflo Weiche" + (strcat "OFWeiche :" (itoa cnt-weichen)) merkmale) + lines)) + ) + + ;; --- Gerade (AP110) --- + ((= typ "gerade") + (setq elem-nr (1+ elem-nr)) + (setq cnt-geraden (1+ cnt-geraden)) + (setq laenge-str (csv:get-attrib ename "LAENGE")) + (if (null laenge-str) (setq laenge-str (csv:get-attrib ename "A"))) + (if (and laenge-str (> (strlen laenge-str) 0)) + (setq len-ap110 (+ len-ap110 (atof laenge-str))) + (setq len-ap110 (+ len-ap110 2000.0)) + ) + (setq merkmale (csv:omni-gerade-merkmale ename rotation)) + (setq lines (cons + (csv:omni-csv-line elem-nr "Omniflo Gerade" + (strcat "OFGerade :" (itoa cnt-geraden)) merkmale) + lines)) + ) + ) ;; cond + + (setq i (1+ i)) + ) ;; while + + ;; Ergebnis ausgeben + (princ (strcat "\n[OMNI_EXPORT] Gefunden: " + (itoa cnt-boegen) " Boegen, " + (itoa cnt-weichen) " Weichen, " + (itoa cnt-geraden) " Geraden")) + + (if (= elem-nr 0) + (princ "\n[OMNI_EXPORT] Keine Omniflo-Elemente gefunden.") + (progn + ;; CSV schreiben + (setq out-pfad (strcat (getenv "DXFM_RESULTS") "/omniflo_export.csv")) + (setq fh (open out-pfad "w")) + (if (null fh) + (princ (strcat "\n[OMNI_EXPORT] FEHLER: Kann Datei nicht oeffnen: " out-pfad)) + (progn + ;; Header + (write-line "Elementnummer;TeileArt;TeileId;Bezeichnung;Anzahl;Merkmale" fh) + ;; Einzelzeilen (lines ist rueckwaerts aufgebaut) + (foreach ln (reverse lines) + (write-line ln fh) + ) + ;; Omniflo Sum Zeile + (write-line + (csv:omni-sum-zeile (1+ elem-nr) + cnt-boegen cnt-wk cnt-einzel cnt-delta cnt-doppel cnt-stern + len-ap110 len-ap60) + fh) + (close fh) + (princ (strcat "\n[OMNI_EXPORT] CSV geschrieben: " out-pfad)) + (princ (strcat "\n[OMNI_EXPORT] Omniflo Sum: " + (itoa cnt-boegen) " Boegen, " + (itoa (+ cnt-einzel cnt-doppel cnt-delta cnt-stern cnt-wk)) " Weichen, " + (rtos len-ap110 2 0) " mm AP110")) + ) + ) + ) + ) + ) + ) + (princ) +) + ;; ============================================================ ;; TEST_FOERDERER - Automatischer Test ohne Benutzereingabe ;; Erzeugt 12 Variofoerderer (6x Auf, 6x Ab) mit deltaL=7000