List of used modelspace named blocks

List of used modelspace named blocks

XXL1966
Contributor Contributor
1,047 Views
5 Replies
Message 1 of 6

List of used modelspace named blocks

XXL1966
Contributor
Contributor

Hello,

 

is it possible to get a list of all currently used and named blocks in the drawing modelspace using tblnext "BLOCK" loop ?

I think the dxf 70 group doesn't tell if it is used or not ...

 

ty

0 Likes
Accepted solutions (1)
1,048 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

I assume that you mean a list of the names of Blocks that are used in Model Space [regardless of how many of each there are], not a list of the Insertions thereof.  If so, try this [lightly tested]:

 

(defun C:MBLIST (/ blk); = Model-space Block LIST

  (while (setq blk (tblnext "block" (not blk))); info on next defined Block

    (if (ssget "_X" (list (assoc 2 blk) '(410 . "Model"))); are there any in Model Space?

      (setq mblist (cons (cdr (assoc 2 blk)) mblist)); then -- add its name to list

    ); if

  ); while

  mblist ; report to Command: line

); defun

 

The mblist variable will contain the list of Blocks that are used in Model Space.

Kent Cooper, AIA
Message 3 of 6

XXL1966
Contributor
Contributor

hello,

 

thx, yes this is what i need but won't this be slow in f.e. large drawings (multiple ssget "x") ?

 

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@XXL1966 wrote:

hello,

 

thx, yes this is what i need but won't this be slow in f.e. large drawings (multiple ssget "x") ?

 


Try it out -- where I am now I don't have any very large drawings to try it in, but I think you'll find it nearly instantaneous.

Kent Cooper, AIA
0 Likes
Message 5 of 6

phanaem
Collaborator
Collaborator
Accepted solution

Another approach

 

(defun get_inserted_blocks (/ blocks ss i e n b l)
  (setq blocks (vla-get-blocks
                 (vla-get-activedocument (vlax-get-acad-object))
               )
  )
  (if
    (setq ss (ssget "X" '((0 . "INSERT") (410 . "Model"))))
     (repeat (setq i (sslength ss))
       (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
             n (vlax-get e
                         (if (vlax-property-available-p e 'effectivename)
                           'effectivename
                           'name
                         )
               )
             b (vla-item blocks n)
       )
       (if
         (and
           (eq (vla-get-isxref b) :vlax-false)
           (not (member n l))
         )
         (setq l (cons n l))
       )
     )
  )
  l
)
Message 6 of 6

XXL1966
Contributor
Contributor

hello,

 

This is indeed the method i already implemented, however i forgot the x-ref check. thx

0 Likes