Message 1 of 5

Not applicable
06-02-2017
06:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm using this code (not written by me) to count specific blocks in a drawing and link this count to a a field:
(defun c:recount (/ block_list cnt env_name) (setq block_list (list (cons '2 "1") (cons '2 "2") (cons '2 "3") ) ) (foreach i block_list (if (setq ss (ssget "X" (list '(0 . "INSERT") i))) (progn (setq cnt (itoa (sslength ss)) env_name (strcat "BLOCK_COUNT_" (cdr i)) ) (setenv env_name cnt) (princ (strcat "\nSet " env_name " to " cnt)) ) (progn (setq cnt "0" env_name (strcat "BLOCK_COUNT_" (cdr i)) ) (setenv env_name cnt) (princ (strcat "\nSet " env_name " to " cnt)) ) ) ) (command "_REGEN") ;_refreshes field values (princ) )
Normally, this is working nicely. However, when I use it for dynamic blocks, the modified ones won't be counted, because of *U anonymous block names. I know the way to solve this would be getting the effective name of the blocks with some code like this one by Lee Mac:
;; Effective Block Name - Lee Mac ;; obj - [vla] VLA Block Reference object (defun LM:effectivename ( obj ) (vlax-get-property obj (if (vlax-property-available-p obj 'effectivename) 'effectivename 'name ) ) )
But I couldn't manage to put it all together. Could anyone give me a hand on this?
Solved! Go to Solution.