; PU1PU2  - Putzstation                                                  ;
; -----------------------------------------------------------------------;
; AW 1.3.98                                                              ;
;------------------------------------------------------------------------;

(defun start()
  (setq auswahl-satz nil)
  (setvar "limcheck" 0)
  (command "_vports" "_S" "aktiv" "_Y")
  (setq BMOD    (getvar "BLIPMODE")
        MOSM    (getvar "OSMODE")
        MSNA    (getvar "SNAPMODE")
        MORT    (getvar "ORTHOMODE")
        CLAY    (getvar "CLAYER")     ; aktuelle Ebene
        MECH    (getvar "MENUECHO")
        BKSYM   (getvar "UCSICON")
        UCSF    (getvar "UCSFOLLOW")
        Z-HOEHE (getvar "THICKNESS")
        ERHEB   (getvar "ELEVATION")
  )
  (princ)
)

(defun Dbox (/ Dat)
  (setq Dat (load_dialog (strcat lw "/acadsst/spinne/pu1pu2.DCL")))
  (if (not (new_dialog "pu1pu2" Dat)) 
    (exit)
  )
;  (set_tile "SPULEN"  m_SPULEN)     ; Spulen pro Spulenzug - default: "36"
;  (set_tile "TEILUNG" m_TEILUNG))   ; Spulenzugteilung - default: "150"
  (set_tile "RICHTUNG" m_RICHTUNG)   ; Drehrichtung - default: "LINKS"
  (set_tile "FUSS"     m_FUSS)       ; FUSS - default: OPPOSITE + VERBUNDEN
  (set_tile "ANTRIEB"  m_ANTRIEB)    ; Reibradantrieb - default: "mit Antrieb" (PU2)
  (set_tile "GERUEST"  m_GERUEST)    ; mit Gerüst
  (set_tile "BEMASS"   m_BEMASS)     ; keine Bemassung
  (SetDia)
  (ACTION_TILE "FUSS" "(zeig_dia)")
  (ACTION_TILE "RICHTUNG" "(zeig_dia)")
  (ACTION_TILE "ANTRIEB" "(zeig_dia)")
  (action_tile "accept" "(SetPara) (done_dialog)")
  (action_tile "cancel" "(exit) (done_dialog)")
  (start_dialog)
  (unload_dialog Dat)
)

(defun SetDia()
  (setq breite (dimx_tile "anzeige"))
  (setq hoehe  (dimy_tile "anzeige"))
  (start_image "anzeige")
  (FILL_IMAGE 0 0 breite hoehe -18)
  (if (and (= m_RICHTUNG "UHR")(= m_ANTRIEB "1")) ; Drehung in uhrzeigersinn+Antrieb
    (progn
      (if (= m_FUSS "ZURUECK") (slide_image 0 0 breite hoehe "spinne(pu2ll)"))
      (if (= m_FUSS "ENTGEGEN")(slide_image 0 0 breite hoehe "spinne(pu2lr)"))
      (if (= m_FUSS "ENTGVERB")(slide_image 0 0 breite hoehe "spinne(pu2lrd)"))
      (if (= m_FUSS "NICHTS") (slide_image 0 0 breite hoehe "spinne(pu2lo)"))
    )
  )
  (if (and (= m_RICHTUNG "GEGENUHR")(= m_ANTRIEB "1")) ; Drehung in gegenuhrzeigersinn+Antrieb
    (progn
      (if (= m_FUSS "ZURUECK") (slide_image 0 0 breite hoehe "spinne(pu2rr)"))
      (if (= m_FUSS "ENTGEGEN")(slide_image 0 0 breite hoehe "spinne(pu2rl)"))
      (if (= m_FUSS "ENTGVERB")(slide_image 0 0 breite hoehe "spinne(pu2rld)"))
      (if (= m_FUSS "NICHTS") (slide_image 0 0 breite hoehe "spinne(pu2ro)"))
    )
  )
  (if (and (= m_RICHTUNG "UHR") (= m_ANTRIEB "0")) ; Drehung in uhrzeigersinn und KEIN Antrieb
    (progn
      (if (= m_FUSS "ZURUECK") (slide_image 0 0 breite hoehe "spinne(pu1ll)"))
      (if (= m_FUSS "ENTGEGEN")(slide_image 0 0 breite hoehe "spinne(pu1lr)"))
      (if (= m_FUSS "ENTGVERB")(slide_image 0 0 breite hoehe "spinne(pu1lrd)"))
      (if (= m_FUSS "NICHTS") (slide_image 0 0 breite hoehe "spinne(pu1lo)"))
    )
  )
  (if (and (= m_RICHTUNG "GEGENUHR")(= m_ANTRIEB "0")) ; Drehung in gegenuhrzeigersinn und KEIN Antrieb
    (progn
      (if (= m_FUSS "ZURUECK") (slide_image 0 0 breite hoehe "spinne(pu1rr)"))
      (if (= m_FUSS "ENTGEGEN")(slide_image 0 0 breite hoehe "spinne(pu1rl)"))
      (if (= m_FUSS "ENTGVERB")(slide_image 0 0 breite hoehe "spinne(pu1rld)"))
      (if (= m_FUSS "NICHTS") (slide_image 0 0 breite hoehe "spinne(pu1ro)"))
    )
  )
  (end_image)
)

(defun zeig_dia()
  (setq m_SPULEN   (get_tile "SPULEN"))
  (setq m_TEILUNG  (get_tile "TEILUNG"))
  (setq m_RICHTUNG (get_tile "RICHTUNG"))   ; Drehrichtung
  (setq m_FUSS     (get_tile "FUSS"))       ; Weichenkonfiguration am Ein- und Ausfahrt
  (setq m_ANTRIEB  (get_tile "ANTRIEB"))    ; Reibradantrieb
  (setq m_GERUEST  (get_tile "GERUEST"))    ; Gerüst
  (setq m_BEMASS   (get_tile "BEMASS"))     ; Bemassung
  (SetDia)
)

(defun SetPara ()
  (setq m_SPULEN   (get_tile "SPULEN"))
  (setq m_TEILUNG  (get_tile "TEILUNG"))
  (setq m_RICHTUNG (get_tile "RICHTUNG"))
  (setq m_FUSS     (get_tile "FUSS"))
  (setq m_ANTRIEB  (get_tile "ANTRIEB"))
  (setq m_GERUEST  (get_tile "GERUEST"))
  (setq m_BEMASS   (get_tile "BEMASS"))
  ;-------------------------------------------------------
  (initget (+ 2 4))
  ;-------------------------------------------------------
)


(defun datain ()  
  ;-------------------------------------------------------
  ;>>>> Eingabeteil <<<<<<<
  ;-------------------------------------------------------
  (if (= m_TEILUNG "0")  ; 150-er Teilung
    (progn
      (setq A '(7250 9050 10850 12650 14450 16250 18050 19850))
      (setq B '(4900 6100 7300 8500 9700 10900 12100 13300))
     )
  )
  (if (= m_TEILUNG "1")  ; 165-er Teilung
    (progn
      (setq A '(7790 9770 11750 13730 15710 17690 19670 21650))
      (setq B '(5260 6580 7900 9220 10540 11860 13180 14500))
     )
  )

  (setq ANZ_SPULEN (atoi m_SPULEN)) ; um Wert NULL zu vermeiden

  (setq ALTFANG (getvar "osmode"))
  (initget (+ 1 2 4))
  (command "_layer" "_m" "A-2" "_c" "2" "" "")
  (command "_ortho" "_off")
  (setq P0 (getpoint "\nPick insertion point : "))
;  (setq P0 (list (car P0) (cadr P0) UK-SCHIENE))
  (bl-name P0) ;--> Block-Name definieren -> Rückgabe: block-kennung
  (setq P1 (list (car p0) (+ (cadr p0) 2650) UK-SCHIENE))
  (if (= m_RICHTUNG "GEGENUHR") ; gegenuhrzeigersinn
    (progn
      (setq P2  (list (+ (nth ANZ_SPULEN A)(car p1)) (- (cadr P1) 200)  UK-SCHIENE))
      (setq P3  (list (car p2)                       (cadr p0)          UK-SCHIENE))
      (setq P4  (list (+ (car p1) 800)               (cadr p1)          UK-SCHIENE))
      (setq P6  (list (car p4)                       (- (cadr p4) 200)  UK-SCHIENE))
      (setq P8  (list (car p4)                       (- (cadr p4) 2650) UK-SCHIENE))
      (setq P10 (list (car p0)                       (+ (cadr p0) 800)  UK-SCHIENE))
      (setq P11 (list (car p0)                       (- (cadr p1) 1050) UK-SCHIENE))
      (setq P15 (list (+ (car p0) 300)               (+ (cadr p0) 300)  0))
    )
    (progn
      (setq P2  (list (+ (nth ANZ_SPULEN A)(car p1)) (cadr P1)          UK-SCHIENE))
      (setq P3  (list (car p2)                       (+ (cadr p0) 200)  UK-SCHIENE))
      (setq P4  (list (+ (car p0) 800)               (cadr p0)          UK-SCHIENE))
      (setq P6  (list (car p4)                       (+ (cadr p4) 200)  UK-SCHIENE))
      (setq P8  (list (car p4)                       (+ (cadr p4) 2650) UK-SCHIENE))
      (setq P10 (list (car p0)                       (+ (cadr p0) 1050) UK-SCHIENE))
      (setq P11 (list (car p1)                       (- (cadr p1) 500)  UK-SCHIENE))
      (setq P15 (list (+ (car p0) 300)               (+ (cadr p0) 500)  0))
    )
  )

  (setq P14 (list (+ (nth ANZ_SPULEN B)(car p0)) (cadr P0)          UK-SCHIENE))
  (command "_ortho" "_on")
  (setvar "osmode" 0)  
  (command "_elevation" "0")
  (command "_ucs" "_w")
  (command "_fill" "_off")
  (setq M_ARTINR "821106002") ; artikel.nr fuer alu-profil APG110
)

(defun geometrie()
  ; ---- Bereich einstellen
  (command "_vpoint" "0,0,1")
  (command "_zoom" "_w" (list (- (car P0) 2000) (- (cadr P0) 2000) 0) 
                        (list (+ (car P2) 2000) (+ (cadr P2) 2000) 0))
  ; --- Putzstation einfügen
  (command "_layer" "_m" "Putzstation" "_c" "5" "" "")
  (command "_insert" (strcat lw "/acadsst/spinne/putzstation") P15 "" "" "")
  (setq auswahl-satz (ssget "_L"))

  (if (= m_RICHTUNG "GEGENUHR") ; in gegenuhrzeigerrichtung
    (progn
      (command "_layer" "_m" "A-2" "_c" "2" "" "")
      (command "_insert" (strcat lw "/acadsst/alu/b1109065") 
                         (list (car P0) (cadr P0) (+ (caddr P0) UK-SCHIENE)) "" "" "180")
      (ssadd (entlast) auswahl-satz)
      (command "_insert" (strcat lw "/acadsst/alu/wbe2r20")  P1 "" "" "")
      (ssadd (entlast) auswahl-satz)
      (if (= m_FUSS "ENTGEGEN")
        (progn
          (command "_insert" (strcat lw "/acadsst/alu/wbe2r20") P2 "" "" "180")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (or (= m_FUSS "ZURUECK") (= m_FUSS "ENTGVERB"))
        (progn
          (command "_insert" (strcat lw "/acadsst/alu/wb2r20") P2 "" "" "180")
          (ssadd (entlast) auswahl-satz)
        )
      )
    
      (gemeinsame-el)

      ; Fuß bearbeiten
      (if (= m_FUSS "ZURUECK")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/b1109065") P3 "" "" "")
          (command "_mirror" (entlast) "" P8 P3 "_Y")
          (ssadd (entlast) auswahl-satz)
          (setq P12 (list (car p2)    (+ (cadr p2) 650) UK-SCHIENE))
          (ap-zeichnen (list (car p3) (+ (cadr p3) 800) UK-SCHIENE) P12)
          (command "_layer" "_m" "A-10" "_c" "8" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/tv80") (list (car p3) (+ (cadr p3) 800) UK-SCHIENE)  "" "" "")
          (ssadd (entlast) auswahl-satz)
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") P12 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGEGEN")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/b1109065") P3 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGVERB")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/sw90l70") P3 "" "" "")
          (ssadd (entlast) auswahl-satz)
          (setq P12 (list (car p2) (+ (cadr p2) 650) UK-SCHIENE))
          (setq P13 (list (car p3) (- (cadr p3) 440) UK-SCHIENE))
          (ap-zeichnen P13 P12)
          (command "_layer" "_m" "A-10" "_c" "8" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") P12 "" "" "")
          (ssadd (entlast) auswahl-satz)
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") P13 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )

      ; zieren
      (command "_layer" "_m" "A-1" "_c" "1" "" "")
      (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") 
                         (list (+ (car p0) 2000) (cadr p0) UK-SCHIENE) "0.5" "" "")
      (ssadd (entlast) auswahl-satz)
      (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") 
                         (list (+ (car p1) 2000) (cadr p1) UK-SCHIENE) "0.5" "" "180")
      (ssadd (entlast) auswahl-satz)
      (if (or (= m_FUSS "ZURUECK") (= m_FUSS "ENTGVERB"))
        (progn 
          (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") 
                             (list (car p3) (+ (cadr p3) 1300) UK-SCHIENE) "0.5" "" "90")
          (ssadd (entlast) auswahl-satz)
        )
      )

      (prompt (strcat "Modul-Länge=" (itoa (+ LAENGE 1650 (* WIEDERHOLE 6000)))))
      (prompt "\n")
    )
  ) ; ENDE (if (= m_RICHTUNG "GEGENUHR")
  
  (if (= m_RICHTUNG "UHR") ; in uhrzeigerrichtung
    (progn
      (command "_layer" "_m" "A-2" "_c" "2" "" "")
      (command "_insert" (strcat lw "/acadsst/alu/wbe2l20") P0 "" "" "180")
      (setq auswahl-satz (ssget "_L"))
      (command "_insert" (strcat lw "/acadsst/alu/b1109065")  P1 "" "" "90")
      (ssadd (entlast) auswahl-satz)
      (if (= m_FUSS "ZURUECK")
        (progn
          (command "_insert" (strcat lw "/acadsst/alu/b1109065") P2 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGEGEN")
        (progn
          (command "_insert" (strcat lw "/acadsst/alu/b1109065") P2 "" "" "180")
          (command "_mirror" (entlast) "" P3 P2 "_Y")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGVERB")
        (progn
          (command "_insert" (strcat lw "/acadsst/alu/sw90r70") P2 "" "" "180")
          (ssadd (entlast) auswahl-satz)
        )
      )

      (gemeinsame-el)

      ; Fuß bearbeiten
      (if (= m_FUSS "ZURUECK")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/wb2l20") P3 "" "" "")
          (ssadd (entlast) auswahl-satz)
          (setq P12 (list (car p2) (- (cadr p2) 800) UK-SCHIENE))
          (ap-zeichnen (list (car p3) (- (cadr p3) 650)  UK-SCHIENE) P12)
          (command "_layer" "_m" "A-10" "_c" "8" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") (list (car p3) (- (cadr p3) 650) UK-SCHIENE) "" "" "")
          (ssadd (entlast) auswahl-satz)
          (command "_insert" (strcat lw "/acadsst/alu/tv80") P12 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGEGEN")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/wbe2l20") P3 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )
      (if (= m_FUSS "ENTGVERB")
        (progn
          (command "_layer" "_m" "A-2" "_c" "2" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/wb2l20") P3 "" "" "")
          (ssadd (entlast) auswahl-satz)
          (setq P12 (list (car p2) (+ (cadr p2) 360) UK-SCHIENE))
          (setq P13 (list (car p3) (- (cadr p3) 650) UK-SCHIENE))
          (ap-zeichnen P13 P12)
          (command "_layer" "_m" "A-10" "_c" "8" "" "")
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") P12 "" "" "")
          (ssadd (entlast) auswahl-satz)
          (command "_insert" (strcat lw "/acadsst/alu/alu_ks") P13 "" "" "")
          (ssadd (entlast) auswahl-satz)
        )
      )

      ; zieren
      (command "_layer" "_m" "A-1" "_c" "1" "" "")
      (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") (list (+ (car p1) 1500) (cadr p1) UK-SCHIENE) "0.5" "" "")
      (ssadd (entlast) auswahl-satz)
      (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") (list (+ (car p0) 1500) (cadr p0) UK-SCHIENE) "0.5" "" "180")
      (ssadd (entlast) auswahl-satz)
      (if (or (= m_FUSS "ZURUECK") (= m_FUSS "ENTGVERB"))
        (progn 
          (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") (list (car p3) (+ (cadr p3) 1300) UK-SCHIENE) "0.5" "" "90")
          (ssadd (entlast) auswahl-satz)
        )
      )

      (prompt (strcat "Modul-Länge=" (itoa (+ LAENGE 1650 (* WIEDERHOLE 6000)))))
      (prompt "\n")
    )
  ) ; ENDE (if (= m_RICHTUNG "UHR")
)


(defun gemeinsame-el()
  ; trapezverbindungselemente 
  (command "_layer" "_m" "A-10" "_c" "8" "" "")
  (command "_insert" (strcat lw "/acadsst/alu/tv80") P4 "" "" "")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/alu/tv80") P6 "" "" "")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/alu/tv80") P8 "" "" "")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/alu/tv80") P10 "" "" "")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/alu/tv80") P11 "" "" "")
  (ssadd (entlast) auswahl-satz)

  ; -- ap träger zeichnen - ABSTAND ermitteln
  (ap-zeichnen P10 P11)
  (setq LAENGE (fix (- (nth ANZ_SPULEN A) 1650)))
  (setq WIEDERHOLE (fix (/ LAENGE 6000))); wenn > 6000 ist der faktor > 0
  (if (> WIEDERHOLE 0)
    (progn
      (repeat WIEDERHOLE
        (setq P5 (list (+ (car p4) 6000) (cadr p4) UK-SCHIENE))
        (ap-zeichnen P4 P5)
        (setq P4 P5) ; punkte vertauschen
        (setq P7 (list (+ (car p6) 6000) (cadr p6) UK-SCHIENE))
        (ap-zeichnen P6 P7)
        (setq P6 P7) ; punkte vertauschen
        (setq P9 (list (+ (car p8) 6000) (cadr p8) UK-SCHIENE))
        (ap-zeichnen P8 P9)
        (setq P8 P9) ; punkte vertauschen
        (setq LAENGE (- LAENGE 6000))
      )
    )
  )

;  (if (= m_RICHTUNG "GEGENUHR")
    (if (= m_FUSS "ENTGEGEN")
      (progn
        (setq P5 (list (+ (car p4) LAENGE 50) (cadr p4) UK-SCHIENE))
        (setq P7 (list (+ (car p6) LAENGE 50) (cadr p6) UK-SCHIENE))
      )
      (progn
        (setq P5 (list (+ (car p4) LAENGE) (cadr p4) UK-SCHIENE))
        (setq P7 (list (+ (car p6) LAENGE) (cadr p6) UK-SCHIENE))
      )
    )
;  )
  (ap-zeichnen P4 P5)
  (ap-zeichnen P6 P7)
  (if (= m_FUSS "ENTGVERB")
    (setq P9 (list (+ (car p8) LAENGE 150) (cadr p8) UK-SCHIENE))
    (setq P9 (list (+ (car p8) LAENGE 50)  (cadr p8) UK-SCHIENE))
  )
 (ap-zeichnen P8 P9)
)

(defun ap-zeichnen (anfang ende)
  (command "_layer" "_m" "A-2" "_c" "2" "" "")
  (bl-name anfang) ;--> Block-Name definieren -> Rückgabe: element-name
  (command "_line" anfang ende "")
  (setq auswahl-ap (ssget "_L"))
  (mach-block anfang "0" AUSWAHL-AP)
  (attribute-aendern "0" "2" "3" (itoa (fix (distance anfang ende))) "" block-kennung
             M_ARTINR (strcat "APG110 L= " (itoa (fix (distance anfang ende)))) "" "")
  (ssadd (entlast) auswahl-satz)
  (setq auswahl-ap nil)
  (command "_layer" "_m" "A-10" "_c" "8" "" "")
  (command "_insert" (strcat lw "/acadsst/alu/tv80") ende "" "" "")
  (ssadd (entlast) auswahl-satz)
)

(defun BEMASSUNG ()
  ;---------
  ; Bemaßung
  ;---------
  (command "_layer" "_m" "A-8" "_c" "8" "" "")
  (command "_dimtad" "0")
  (command "_dimtxt" "125")
  (command "_dimasz" "40")
;  (setvar "osmode" 0)
  (command "_dimaligned" P0 P1 (list (- (car p0) 400) (cadr p0) 0))
  (ssadd (entlast) auswahl-satz)
  (command "_dimlinear" P11 P2 (list (- (car p11) 400) (cadr p11) 0))
  (ssadd (entlast) auswahl-satz)
  (if (= m_BEMASS "1")
    (progn
      (command "_layer" "_m" "F-8" "_c" "8" "" "")
      (command "_dimlinear" P0 P14 (list (+ (car p0) 2000) (- (cadr p0) 400) 0 ))
      (ssadd (entlast) auswahl-satz)
    )
  )
)

(defun motor()
  (if (= m_RICHTUNG "GEGENUHR")
    (progn
      (command "_layer" "_m" "F-1" "_c" "1" "" "")
      (command "_insert" (strcat lw "/acadsst/foerder/ra1") P14 "" "" "") 
      (command "_insert" (strcat lw "/acadsst/foerder/ra2_200") (list (car P14) (+ (cadr P14) 2450) UK-SCHIENE) "" "" "") 
    )
  )
  (if (= m_RICHTUNG "UHR")
    (progn
      (command "_layer" "_m" "F-1" "_c" "1" "" "")
      (command "_insert" (strcat lw "/acadsst/foerder/ra2_200") P14 "" "" "") 
      (command "_insert" (strcat lw "/acadsst/foerder/ra1") (list (car P14) (+ (cadr P14) 2650) UK-SCHIENE) "" "" "") 
    )
  )
)

; ---- GERUEST zeichnen ----------------------------------------------------
(defun structure ()
  (setq T1 (list (- (car p0) 600)  (- (cadr p0) 1175) UK-GERUEST))
  (setq T2 (list (+ (car p0) 1400) (- (cadr p0) 1175) UK-GERUEST))
  (setq T3 (list (- (car p3) 1400) (- (cadr p0) 1175) UK-GERUEST))
  (setq T4 (list (+ (car p3) 600)  (- (cadr p0) 1175) UK-GERUEST))
  (setq T5 (list (car t1)          (- (cadr p0) 325)  UK-GERUEST))
  (setq T6 (list (+ (car P0) 100)  (- (cadr p0) 325)  UK-GERUEST))

  ; ---- eine 3-Fläche als Unterlage zeichnen
  (command "_layer" "_m" "Boden" "_c" "8" "" "")
  (command "_3dface" (list (car T1) (cadr T1) 0) (list (car T4) (cadr T4) 0)
                     (list (car T4) (+ (cadr T4) 5000) 0) (list (car T1) (+ (cadr T4) 5000) 0) "")
  (ssadd (entlast) auswahl-satz)

  ; ---- RT80/80 zeichnen ---------------------------------------------------
  (setq auswahl-rt nil)
  (command "_layer" "_m" "D-5" "_c" "5" "" "")
  ; -- das kurze Stück zwischen DRT80
  (bl-name T6) ;--> Block-Name definieren -> Rückgabe: element-name
  (command "_line" (list (car T6) (+ (cadr T6) 35) (caddr T6)) (list (car T6) (+ (cadr T6) 3265) (caddr T6)) "")
  (setq auswahl-rt (ssget "_L"))
  (mach-block T1 "0" AUSWAHL-rt)
  (attribute-aendern "0" "2" "5" "3230" "115-115" block-kennung 
                     "825144004" "RT 80/80 L= 3230" "" "")
  (ssadd (entlast) auswahl-satz)
  (if (not (= m_FUSS "NICHTS"))
    (progn
      (command "_copy" (entlast) "" T6 (list (+ (car T6) (- (fix (distance T1 T4)) 1400)) (cadr T6) (caddr T6)))
      (ssadd (entlast) auswahl-satz)
    )
  )
  (setq auswahl-rt nil)
  (bl-name T1) ;--> Block-Name definieren -> Rückgabe: element-name
  (command "_line" T1 (list (car T1) (+ (cadr T1) 5000) (caddr T1)) "")
  (setq auswahl-rt (ssget "_L"))
  (mach-block T1 "0" AUSWAHL-rt)
  (attribute-aendern "0" "2" "5" "5000" "250-250" block-kennung 
                     "825144005" "RT 80/80 L= 5000" "" "")
  (ssadd (entlast) auswahl-satz)
  (setq auswahl-rt nil)

  ; -------- wie oft kopieren ? -------------------------------------------
  (setq wieoft (+ (fix (/ (distance P0 P3) 3000)) 1))
  (setq copyabstand (fix (/ (distance P0 P3) wieoft)))
  (setq wieoft (- wieoft 2))
  (copy_element T1 T2 T3 T4)

  ; --- DRT 80 -> 1-mal zeichnen und 4 mal kopieren
  (command "_layer" "_m" "D-1" "_c" "1" "" "")
  (bl-name T5) ;--> Block-Name definieren -> Rückgabe: element-name
  (command "_line" (list (+ (car T5) 35)   (cadr T5) (caddr T5)) 
                   (list (+ (car T5) 1965) (cadr T5) (caddr T5)) "")
  (setq auswahl-rt (ssget "_L"))
  (mach-block T5 "0" AUSWAHL-rt)
  (attribute-aendern "0" "2" "5" "1930" "250-180" block-kennung 
                     "825084002" "DRT 80 L= 1930" "" "")
  (ssadd (entlast) auswahl-satz)
  (setq auswahl-rt nil)
  (command "_copy" (entlast) "" T5 (list (car T5) (+ (cadr T5) 3300) (caddr T5)))
  (ssadd (entlast) auswahl-satz)
  (if (not (= m_FUSS "NICHTS"))
    (progn
      (command "_copy" (entlast) "" (list (car T5)                            (+ (cadr T5) 3300) (caddr T5)) 
                                    (list (+ (car T5) (fix (distance T1 T3))) (+ (cadr T5) 3300) (caddr T5)))
      (ssadd (entlast) auswahl-satz)
      (command "_copy" (entlast) "" (list (+ (car T5) (fix (distance T1 T3))) (+ (cadr T5) 3300) (caddr T5))
                                    (list (+ (car T5) (fix (distance T1 T3))) (cadr T5)          (caddr T5)))
      (ssadd (entlast) auswahl-satz)
    )
  )

  ; 2" Säulen ---------------------------------------------------------
  (setq AUSWAHL-STR nil)
  (setq TS1 (list (car T1) (- (cadr T1) 35) 0))
  (setq TS2 (list (car T2) (- (cadr T2) 35) 0))
  (setq TS3 (list (car T3) (- (cadr T3) 35) 0))
  (setq TS4 (list (car T4) (- (cadr T4) 35) 0))
  (command "_layer" "_m" "D-1" "_c" "1" "" "")
  (bl-name T1) ;--> Block-Name definieren -> Rueckgabe: element-name
  (setq PT1 (list (- (car TS1) 100) (- (cadr TS1) 150) 0))
  (setq PT2 (list (+ (car TS1) 100) (- (cadr TS1) 150) 0))
  (setq PT3 (list (+ (car TS1) 100) (+ (cadr TS1) 150) 0))
  (setq PT4 (list (- (car TS1) 100) (+ (cadr TS1) 150) 0))
  (setvar "thickness" 10)
  (setvar "elevation" 0)
  (command "_solid" PT1 PT2 PT4 PT3 "")
  (setq AUSWAHL-STR (ssget "_L"))
  (setvar "thickness" 2990)
  (setvar "elevation" 10)  
  (command "_circle" TS1 "30")
  (ssadd (entlast) AUSWAHL-STR)
  (setvar "thickness" 0)
  (setvar "elevation" 0)
  (mach-block TS1 "0" AUSWAHL-STR)
  (attribute-aendern "0" "0" "25" "3000" "" block-kennung "821004025" "SL 2\" mit Fussplatte" "" "")
  (ssadd (entlast) auswahl-satz)
  (setq AUSWAHL-STR nil)
  (copy_element TS1 TS2 TS3 TS4)

  ; ----- UPAT Duebel 4 Stück ----------------------------------------
  (command "_layer" "_m" "D-10" "_c" "10" "" "")
  (setq WINKEL 0)
  (setvar "thickness" 0)
  (setvar "elevation" 0)
  (command "_insert" (strcat lw "/acadsst/rohr/d_einzel") TS1 "" "" (rtos WINKEL)) 
  (attribute-aendern "0" "0" "25" "" "" block-kennung "922021003" "HST M12/20" "4" "")     
  (ssadd (entlast) AUSWAHL-SATZ)
  (copy_element TS1 TS2 TS3 TS4)
  (setq WINKEL (+ WINKEL 5))
  (command "_insert" (strcat lw "/acadsst/rohr/d_einzel") TS1 "" "" (rtos WINKEL)) 
  (attribute-aendern "0" "0" "25" "" "" block-kennung "923014001" "UPAT PSL-ANKER TYP B 14/10" "4" "")
  (ssadd (entlast) AUSWAHL-SATZ)   
  (copy_element TS1 TS2 TS3 TS4)

  ; ---- KLEMMRING EINFACH
  (command "_layer" "_m" "D-4" "_c" "4" "" "")
  (command "_insert" (strcat lw "/acadsst/rohr/" "D_1KR") (list (car TS1) (cadr TS1) 2620) "" "" "")
  (ssadd (entlast) AUSWAHL-SATZ)
  (copy_element TS1 TS2 TS3 TS4)
  (command "_insert" (strcat lw "/acadsst/rohr/" "D_1KR") (list (car TS1) (cadr TS1) 2500) "" "" "")
  (ssadd (entlast) AUSWAHL-SATZ)
  (copy_element TS1 TS2 TS3 TS4)

  ; Säulen und Klemmringe spiegeln auf die andere Seite
  (command "_mirror" "_w" (list (- (car T1) 500) (- (cadr T1) 500)  0) 
                          (list (+ (car T4) 500) (+ (cadr T4) 500)  4000) "" 
                          (list (car P0)         (+ (cadr P0) 1325) 0) 
                          (list (+ (car P0) 500) (+ (cadr P0) 1325) 0) "_N"
  )
)

 
; ---- ELEMENTE KOPIEREN -----------------------------------------------------------------
(defun copy_element (TK1 TK2 TK3 TK4)
  (command "_copy" (entlast) "" TK1 TK2)
  (ssadd (entlast) auswahl-satz)
  (setq AP_BEF_90 (+ AP_BEF_90 3)) ; Rohrschelle für AP kpl.
  (setq TM  (list (+ (car TK1) 2000) (cadr TK1) (caddr TK1)))
  (repeat wieoft
    (setq TN (list (+ (car TM) copyabstand) (cadr TM) (caddr TM)))
    (command "_copy" (entlast) "" TM TN)
    (ssadd (entlast) auswahl-satz)
    (setq AP_BEF_90 (+ AP_BEF_90 3)) ; Rohrschelle für AP kpl.
    (setq TM TN)
  )
  (command "_copy" (entlast) "" TM TK3)
  (ssadd (entlast) auswahl-satz)
  (setq AP_BEF_90 (+ AP_BEF_90 3)) ; Rohrschelle für AP kpl.
  (if (not (= m_FUSS "NICHTS"))
    (progn
      (command "_copy" (entlast) "" TK3 TK4)
      (ssadd (entlast) auswahl-satz)
    )
  )
)

(defun schluss()
  (IF clay
    (progn
      (command "_layer" "_set" clay "") 
      (setvar "BLIPMODE"  bmod)
      (setvar "CMDECHO"   1)
      (setvar "MENUECHO"  mech)
      (setvar "OSMODE"    mosm)
      (setvar "SNAPMODE"  msna)
      (setvar "ORTHOMODE" mort)
      (setvar "UCSICON"   bksym)
      (setvar "UCSFOLLOW" ucsf)
      (setvar "THICKNESS" Z-HOEHE)
      (setvar "ELEVATION" ERHEB)
    )
  )
  (command "_vports" "_R" "aktiv")
  (princ)
)

;------------------------------------------------------------------------------
(defun c:pu1pu2 ( / A B C P1 P2 P3 p4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15
                    T1 T2 T3 T4 T5 TS1 TS2 TS3 TS4 AUSWAHL-STR UK-SCHIENE UK-GERUEST AB_BEF_90 
                    AB_BEF_BOG DRT80_8080 BMOD MOSM MSNA MORT CLAY MECH BKSYM UCSF HOEHE ERHEB BREITE
                    Z-HOEHE)
  (start)
  (setq auswahl-ap   nil) ; auswahlsatz fuer die Bildung der traeger
  (prompt "******* SPINNING MODULES - CLEANING STATIONS P1 & P2 *******")
  (prompt "")
  (setq UK-SCHIENE 2390)
  (setq UK-GERUEST 2500)
  ; --- Zaehler für die Ermittlung der Kleinteile
  ; --- Die Kleinteile werden auf D-10 in P0 gesetzt 
  (setq AP_BEF_90  0) ; Rohrschelle für AP kpl.  821114019 - Abhängig von der Länge - pro RT80/80 3 Stück
  (setq AP_BEF_BOG 5) ; Bogenschelle für AP kpl. 821114028 - am Ende des Moduls
  (setq DRT80_8080 4) ; ?????????????????????
  
  (if (null m_SPULEN)   (setq m_SPULEN   "0"))              ; Spulen pro Spulenzug - default: "36"
  (if (null m_TEILUNG)  (setq m_TEILUNG  "0"))              ; Spulenzugteilung - default: "150"
  (if (null m_RICHTUNG) (setq m_RICHTUNG "GEGENUHR"))       ; Drehrichtung - default: "gegenuhrzeigersinn"
  (if (null m_FUSS)     (setq m_FUSS     "ENTGVERB"))       ; FUSS 
  (if (null m_ANTRIEB)  (setq m_ANTRIEB  "1"))              ; Reibradantrieb - default: "mit Antrieb" (PU2)
  (if (null m_GERUEST)  (setq m_GERUEST  "1"))              ; mit Gerüst
  (if (null m_BEMASS)   (setq m_BEMASS   "0"))              ; keine Bemassung
  ;-------------------------------------------------------------------------------------------------------
  (Dbox)
  (datain)
  (geometrie)
  (if (= m_BEMASS "1")
    (bemassung)
  )
  (if (= m_ANTRIEB "1")
    (motor)
  )
  (if (= m_GERUEST "1")
    (structure)
  )  
;  (mach-block P0 "0" auswahl-satz)
;  (command "_rotate" "_l" "" P0 pause)
  ; --- Die Kleinteile in 0,0
  (command "_layer" "_m" "D-10" "_c" "10" "" "")
  (setq WINKEL 0)
  (setvar "thickness" 0)
  (setvar "elevation" 0)
  ; ---- Rohrschelle für AP kpl. (für die geraden Stücke)
  (command "_insert" (strcat lw "/acadsst/rohr/d_einzel") P0 "" "" (rtos WINKEL)) 
  (attribute-aendern "0" "0" "25" "" "" block-kennung "821114019" "Rohrschelle für AP kpl." (rtos AP_BEF_90) "")     
  (setq WINKEL (+ WINKEL 5))
  ; ---- Bogenschelle für AP kpl. (für die Bögenabhängung)
  (command "_insert" (strcat lw "/acadsst/rohr/d_einzel") P0 "" "" (rtos WINKEL)) 
  (attribute-aendern "0" "0" "25" "" "" block-kennung "821114028" "Bogenschelle für AP kpl." (rtos AP_BEF_BOG) "")     
  (setq WINKEL (+ WINKEL 5))
  ; ---- DRT 80 an RT80/80 ????????????????
  (command "_insert" (strcat lw "/acadsst/rohr/d_einzel") P0 "" "" (rtos WINKEL)) 
  (attribute-aendern "0" "0" "25" "" "" block-kennung "?????????" "????????" (rtos DRT80_8080) "")     
  (setq WINKEL (+ WINKEL 5))
  ; ---- ENDE der Einfügug der Kleinteile

  (command "_rotate" auswahl-satz "" P0 pause)
  (schluss)
)
