hans409
Computer
- Oct 30, 2005
- 1
The below lisp gives me an error. Can anyone help me out?
;Tip1752: LIST_ELEM.LSP List blocks (C)2001, Andrzej Gumula
; *********** Modified to just 'list' to 'drawingname'.txt file.
; Modified by: Bob Shaw (ECCAD)
; Lisp for make list of Blocks or Shape in selected ASCII file
(defun ADD (A B / C)
(while (/= A (car C))
(setq C (car B)
B (cdr B)
)
) ;end while
(cdr C)
) ;end add
(defun C:LIST_ELEM (/ CM RYS WHAT ZBIOR TEMP NAME ITEM LISTA FILE)
(setq CM (getvar "cmdecho")
RYS (getvar "dwgname")
LISTA NIL
)
(setvar "cmdecho" 0)
(initget "Insert Shape")
(setq WHAT (cond ((getkword "\nShapes,<Insert blocks>: "))
(t "INSERT")
)
)
(cond ((setq ZBIOR (ssget (list (cons 0 (strcase WHAT)))))
(repeat (setq TEMP (sslength ZBIOR))
(setq TEMP (1- TEMP)
NAME (cdr (assoc 2 (entget (ssname ZBIOR TEMP))))
)
(cond ((not (member NAME (mapcar 'car LISTA)))
(setq LISTA (append LISTA (list (cons NAME 1))))
)
(t
(setq ITEM (ADD NAME LISTA)
LISTA (subst (cons NAME (1+ ITEM)) (cons NAME ITEM) LISTA)
)
)
) ;end cond
) ;end repeat
; Old code here
; (cond ((setq NAME (getfiled "FILE WITH LIST OF ELEMENTS"
; (substr RYS 1 (- (strlen RYS) 4))
; "txt"
; 1
; )
; )
; (setq FILE (open NAME "w"))
; (foreach X LISTA
; (write-line (strcat (car X) " " (itoa (cdr X))) FILE)
; )
; (setq FILE (close FILE))
; )
; (t (prompt "\nNo file selected. "))
; )
; )
; (t (prompt "\nNothing selected. "))
; ) ;end cond
; New code here
(setq NAME (strcat (substr RYS 1 (- (strlen RYS) 4)) ".txt"))
(setq FILE (open NAME "w"))
(foreach X LISTA
(write-line (strcat (car X) " " (itoa (cdr X))) FILE)
); foreach
(setq FILE (close FILE))
;; end of new code
(setvar "cmdecho" CM)
(princ)
) ;end file
(prompt "\nLoaded new command LIST_ELEM. ")
(princ)
;Tip1752: LIST_ELEM.LSP List blocks (C)2001, Andrzej Gumula
; *********** Modified to just 'list' to 'drawingname'.txt file.
; Modified by: Bob Shaw (ECCAD)
; Lisp for make list of Blocks or Shape in selected ASCII file
(defun ADD (A B / C)
(while (/= A (car C))
(setq C (car B)
B (cdr B)
)
) ;end while
(cdr C)
) ;end add
(defun C:LIST_ELEM (/ CM RYS WHAT ZBIOR TEMP NAME ITEM LISTA FILE)
(setq CM (getvar "cmdecho")
RYS (getvar "dwgname")
LISTA NIL
)
(setvar "cmdecho" 0)
(initget "Insert Shape")
(setq WHAT (cond ((getkword "\nShapes,<Insert blocks>: "))
(t "INSERT")
)
)
(cond ((setq ZBIOR (ssget (list (cons 0 (strcase WHAT)))))
(repeat (setq TEMP (sslength ZBIOR))
(setq TEMP (1- TEMP)
NAME (cdr (assoc 2 (entget (ssname ZBIOR TEMP))))
)
(cond ((not (member NAME (mapcar 'car LISTA)))
(setq LISTA (append LISTA (list (cons NAME 1))))
)
(t
(setq ITEM (ADD NAME LISTA)
LISTA (subst (cons NAME (1+ ITEM)) (cons NAME ITEM) LISTA)
)
)
) ;end cond
) ;end repeat
; Old code here
; (cond ((setq NAME (getfiled "FILE WITH LIST OF ELEMENTS"
; (substr RYS 1 (- (strlen RYS) 4))
; "txt"
; 1
; )
; )
; (setq FILE (open NAME "w"))
; (foreach X LISTA
; (write-line (strcat (car X) " " (itoa (cdr X))) FILE)
; )
; (setq FILE (close FILE))
; )
; (t (prompt "\nNo file selected. "))
; )
; )
; (t (prompt "\nNothing selected. "))
; ) ;end cond
; New code here
(setq NAME (strcat (substr RYS 1 (- (strlen RYS) 4)) ".txt"))
(setq FILE (open NAME "w"))
(foreach X LISTA
(write-line (strcat (car X) " " (itoa (cdr X))) FILE)
); foreach
(setq FILE (close FILE))
;; end of new code
(setvar "cmdecho" CM)
(princ)
) ;end file
(prompt "\nLoaded new command LIST_ELEM. ")
(princ)