×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

block count lisp

block count lisp

block count lisp

(OP)
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)

RE: block count lisp

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources