;---------------------------------
; Stckliste einfgen 21.5.93 AW
;---------------------------------
(Defun C:stcklimp ( / P1 P2 P3 P4 P5 P6 P11 P12 P91 P92 P93 P94 P95
                  kette1 kette2 kette3 kette4 kette5 tsize lspace ebene
                  efnam crntl)
  (Setvar "Cmdecho" 0)
  (setq ALTFANG (getvar "osmode"))
  (setvar "osmode" 0)
  (initget (+ 2 4))
  (setq EBENE (getint "\nStckliste fr Stahl-Str(1) / ALU(2) / DRT(3) / PROFIL(4) / ELEKTRIK(5) <1>: "))
  (if (or (= EBENE nil) (< EBENE 1) (> EBENE 5))
     (setq EBENE 1)
  )
  (if (= EBENE 1)
     (command "_layer" "_m" "L-8" "_c" "8" "" "")
  )
  (if (= EBENE 2)
     (command "_layer" "_m" "A-8" "_c" "8" "" "")
  )
  (if (= EBENE 3)
     (command "_layer" "_m" "D-8" "_c" "8" "" "")
  )
  (if (= EBENE 4)
     (command "_layer" "_m" "P-8" "_c" "8" "" "")
  )
  (if (= EBENE 5)
     (command "_layer" "_m" "E-8" "_c" "8" "" "")
  )


  (If (= EFNAM nil) 
     (Setq EFNAM "")
  )
  (Setq 
    X (Getfiled "Auswahl Zeichnugsstcklistendatei" (strcat lw "/daten/cad/") "zei" 8 )
  )

  (If (/= X "") (Setq EFNAM X))
  (Setq EFPNT (Open EFNAM "r"))
  (If (= EFPNT nil)
      (alert (Strcat "\n"(Chr 34) EFNAM (Chr 34) 
                     ": Datei kann nicht ge”ffnet werden!"))
      (Progn
        (Setq CRNTL (Read-line EFPNT))
        (Setq CRNTL (Read-line EFPNT))
        (setq TSIZE 150 LSPACE 300)
        (initget (+ 1 2 4))
        (setq P1 (getpoint "\nObere-linke Ecke der Stckliste antippen: "))

        (Setq P11 (List (- (Car P1) 100)  (+ (Cadr P1) 250)))
        (Setq P12 (List (+ (Car P1) 8000) (+ (Cadr P1) 250)))

        (command "_line" P11 P12 (list (car P12) (+ (cadr P12) 350))
                        (list (car P11) (+ (cadr P11) 350)) P11 "")

        (Setq P91 (List (+ (Car P11) 400)  (+ (Cadr P11) 100)))
        (Setq P92 (List (+ (Car P11) 800)  (+ (Cadr P11) 100)))
        (Setq P93 (List (+ (Car P11) 1450) (+ (Cadr P11) 100)))
        (Setq P94 (List (+ (Car P11) 2050) (+ (Cadr P11) 100)))
        (Setq P95 (List (+ (Car P11) 3250) (+ (Cadr P11) 100)))
        (Command "_Text" P91 TSIZE 0 "POS")
        (Command "_Text" P92 TSIZE 0 "MENGE")
        (Command "_Text" P93 TSIZE 0 "LŽNGE")
        (Command "_Text" P94 TSIZE 0 "ARTIKEL-NR")
        (Command "_Text" P95 TSIZE 0 "BEZEICHNUNG")

        (While CRNTL

            (setq kette1 (substr crntl 1 6))     ;POSITION
            (setq kette2 (substr crntl 7 6))     ;MENGE
            (setq kette3 (substr crntl 13 9))    ;MASS
            (setq kette4 (substr crntl 22 10))   ;ARTINR
            (setq kette5 (substr crntl 32 40))   ;BEZEICHNUNG
            (Setq P2 (List (+ (Car P1) 400) (Cadr P1)))
            (Setq P3 (List (+ (Car P1) 1000) (Cadr P1)))
            (Setq P4 (List (+ (Car P1) 1900) (Cadr P1)))
            (Setq P5 (List (+ (Car P1) 3000) (Cadr P1)))
            (Setq P6 (List (+ (Car P1) 8000) (Cadr P1)))
            (Command "_Text" P1 TSIZE 0 kette1)
            (Command "_Text" P2 TSIZE 0 kette2)
            (Command "_Text" P3 TSIZE 0 kette3)
            (Command "_Text" P4 TSIZE 0 kette4)
            (Command "_Text" P5 TSIZE 0 kette5)
            (command "_line" (list (- (car P1) 100) (- (cadr P1) 50))
                             (list (car P6) (- (cadr P6) 50)) "")

            (Setq P1 (List (Car P1) (- (Cadr P1) LSPACE)))
            (Setq CRNTL (Read-line EFPNT))
        )
        (Close EFPNT)
        (command "_line" P11 P12 (list (+ (car P1) 8000) (- (cadr P1) 50))
                                 (list (- (car P1) 100) (- (cadr P1) 50))
                         P11 "")
        (setvar "osmode" ALTFANG)
        
      )
  )
  (Princ)
)
