Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations The Obturator on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

block count lisp

Status
Not open for further replies.

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)

 
Replies continue below

Recommended for you

hans409,

At a quick first glance, I noticed that you haven't set the variable B to contain a list at the beginning of the code. You have set C to be car B, and then B to be cdr of itself. When you are first running this, there are no lists set to these variables.

Hope this helps,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor