JOLMOR Posted February 23, 2022 Posted February 23, 2022 (edited) Greetings, I am looking for a Lisp routine to count number of objects within a block, and put the result inside of an existing text like a field. I found in Autodesk forum the next lisp routine that count the entities and their respective entity type, but from all blocks of the drawing at the same time, and I need to count each block, one by one plus the result linked to a text field (just the quantity as a number, nothing else. I am not interested in the entity type of the elements). Somebody could help me with this, please... thanks a lot. (defun c:cnt(/ blo doc js lst n tbl) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for blo (vla-get-blocks doc) (or (wcmatch (vla-get-name blo) "`**,*|*") (eq (vla-get-isxref blo) :vlax-true) (progn (setq lst nil) (vlax-for ent blo (setq tbl (cons (vla-get-objectname ent) tbl)) ) (while tbl (setq n (length tbl) js (car tbl) tbl (vl-remove js tbl) lst (cons (cons (itoa (- n (length tbl))) js) lst) ) ) (princ (strcat "\nWe have in the block : " (vla-get-name blo))) (foreach n (vl-sort lst '(lambda (a b) (< (cdr a) (cdr b)))) (princ (strcat "\n" (substr " " 1 (- 5 (strlen (car n)))) (car n) " " (substr (cdr n) 5) ) ) ) ) ) ) (princ) ) Edited February 23, 2022 by SLW210 Add Code Tags Quote
ronjonp Posted February 23, 2022 Posted February 23, 2022 Try this: (defun c:cnt (/ r) (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (= 0 (vlax-get b 'isxref) (vlax-get b 'islayout)) (setq r (cons (cons (vla-get-name b) (vla-get-count b)) r)) ) ) (mapcar 'print (vl-sort r '(lambda (a b) (< (car a) (car b))))) (princ) ) (vl-load-com) Quote
mhupp Posted February 23, 2022 Posted February 23, 2022 Use this to quickly see if their are nested blocks in my drawing. https://cadtips.cadalyst.com/edit-blocks/nested-block-tree-display Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.