Jump to content

Select Dynamic Blocks By Name


harilalmn

Recommended Posts

Hi All,

Is there a way to select all instances of a dynamic block in the drawing by picking one?

 

This is an attempt to "Select by name". But dynamic blocks kills my code below as they have fancy naming (Like *U24)

 

So far I am here...

 

(defun c:SB ()
 (setq TargEnt (car (entsel "\nSelect block : ")))
 (setq blkname (EffectiveName TargEnt))
 (setq ss (ssget "_X" (list (cons 0 "insert")(cons 2 blkname))))
 (sssetfirst nil ss)
 (princ)
)

;Code below is the courtesy of 'irneb' on http://forums.augi.com/showthread.php?t=114752
(defun EffectiveName (en / ed d1 d2 d3 br)
 (setq ed (entget en))
 (setq d1 (entget (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") ed)))))
 (setq d2 (entget (cdr (assoc 360 (member '(3 . "AcDbBlockRepresentation") d1)))))
 (setq d3 (entget (cdr (assoc 360 (member '(3 . "AcDbRepData") d2)))))
 (setq br (entget (cdr (assoc 340 d3))))
 (cdr (assoc 2 br))
)

Link to comment
Share on other sites

Select your single block instance, and extract the block's name, then create a selection set of all blocks with that, or annonymous names. Next iterate through that selection set and check for matches against the original block's EffectiveName and IsDynamicBlock Properties.

 

Sample:

...
(setq ss (ssget "x" (list (cons 2 "[color=red]<BlockName>[/color],`*U*"))))
...

 

HTH

Link to comment
Share on other sites

I made the same question long ago... I couldn't remember who helped me then...

 


(defun c:sb    (/ e name n out ss x rjp-getblockname)
(vl-load-com)
(prompt "\n   Pick BLOCK to acquire its instances in the drawing...") 
 (defun rjp-getblockname (obj)
   (if    (vlax-property-available-p obj 'effectivename)
     (vla-get-effectivename obj)
     (vla-get-name obj)
   )
 )
 (if (setq x     (ssget '((0 . "INSERT")))
       x     (ssname x 0)
       name (rjp-getblockname (vlax-ename->vla-object x))
       ss     (ssget "_X" '((0 . "INSERT")))
       n     -1
       out     (ssadd)
     )
   (while (setq e (ssname ss (setq n (1+ n))))
     (if (= (rjp-getblockname (vlax-ename->vla-object e)) name)
   (ssadd e out)
     )
   )
 )
 (sssetfirst nil out)
 (princ)
)

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...