Jump to content

How to identify block instance


bwencadtutor

Recommended Posts

Help needed!

In Model Space, there are many block instances with different attributes value of one block reference, how can I identify each instance ?

 

I am trying to list all attributes value of each instance of this one block reference.

 

Thanks

 

Bing

Link to comment
Share on other sites

I would just use something like this:

 

(defun c:getatts  (/ bdef blk ss att aLst attLst)
 (vl-load-com)
 (setq bdef (getvar "INSNAME"))
 (while (not blk)
   (setq blk (getstring t (strcat "\nSpecify Block to be Searched <" bdef ">: ")))
   (cond ((eq "" blk)
          (setq blk bdef))
         ((and (snvalid blk)
               (tblsearch "BLOCK" blk)))
         (T (setq blk  nil bdef ""))))
 (if (setq ss (ssget "X" (list (cons 0 "INSERT")
                               (cons 2 blk)
                               (cons 66 1)
                               (if (getvar "CTAB")
                                 (cons 410 (getvar "CTAB"))
                                 (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (foreach x  (mapcar 'cadr (ssnamex ss))
       (setq att (entnext x))
       (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
         (setq attLst (cons (cons (cdr (assoc 2 aLst))
                                  (cdr (assoc 1 aLst))) attLst)
               att    (entnext att))))
     (alert (vl-princ-to-string (reverse attLst))))
   (princ "\n<!> No Blocks Found <!>"))
 (princ))

 

Will list all attributes as an associative list in the format:

 

( . )

Link to comment
Share on other sites

Hi

 

You can replace this

(foreach x  (mapcar 'cadr (ssnamex ss))
       (setq att (entnext x))
       (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
         (setq attLst (cons (cons (cdr (assoc 2 aLst))
                                  (cdr (assoc 1 aLst))) attLst)
               att    (entnext att))))
     (alert (vl-princ-to-string (reverse attLst)))

by

(vlax-for bl (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
 (setq attlst (mapcar '(lambda(x) (cons (vla-get-tagstring x) (vla-get-textstring x))) (vlax-invoke bl 'getattributes)))
)
(vla-delete sel)
(alert (vl-princ-to-string attlst))

@+

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...