Results 1 to 8 of 8

Thread: Select all occurences of a Dynamic Block in Modelspace

  1. #1
    Member
    Join Date
    2006-08
    Location
    Fairfax, VA
    Posts
    13
    Login to Give a bone
    0

    Default Select all occurences of a Dynamic Block in Modelspace

    What I'd like to do is create a selection set of all the instances of a specific dynamic block, in model space only. I'm trying two different approaches:

    Using Selection Set Filtering:

    (setq ss (ssget "_x" (list (cons 410 "Model")(cons 0 "Insert"))))

    That selects all of the blocks (and XREF's, presumably) in model space. If this were not a dynamic block, I could add (cons 2 "blockname") to filter the set. Of course, the "name" of my dynamic block changes with each insert, to something like "*U8".

    In comparing one of my dynamic blocks to a static block, I noticed the following DXF entries for the DB only:
    (102 . "{ACAD_XDICTIONARY")
    (360 . <Entity name: 7ef14620>)
    (102 . "}")

    Is this the key to determining whether an item is a dynamic block (and subsequently checking for its name)? I considered filtering for 360=non-nil, but I don't know what else that might include.

    Using the Object Model:

    (setq Modelspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))

    That gets me down to modelspace, but I cannot figure out how to select only the blocks (better yet, only dynamic blocks, or only the one I specify).

    Any help would be greatly appreciated.

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    This will get a list of all blocks ( dynamic or not ) within model space that match the supplied name.

    Code:
    (vlax-for obj (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
        (if
            (and
                (= (vla-get-ObjectName obj) "AcDbBlockReference")
                (= (vla-get-EffectiveName obj) "EnterYourBlockNameHere")
            )
            (setq BlkList (cons obj BlkList))
        )
    )

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    Or you can use a similar method as in my select similar routine attached. Save both to somewhere in support paths. Load the LSP, Type SelSimilar at command. Pick an eaxmple object, press Enter / Space to open the settings dialog. In the Block Name setting, change to Effective.

    Nice thing here is the ssget only highlights the blocks in question, since it filters for the Effective Name as well as all the anonymous block names of that DB.
    Attached Files Attached Files

  4. #4
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    Hi,

    You can try this routine.
    SSD allows to select dynamic blocks according to their dynamic properties values

    Code:
    ;;; SSD R2.3 (gile) 14/07/2008
    ;;; Select dynamic blocks according to dynamic properties values
    ;;; Using:
    ;;; To make a selection, enter ssd at command prompt or,
    ;;; within a modification command, type (ssd) at "Select objects: " prompt
    ;;; Select a source dynamic block
    ;;; Choose properties values to filter in the dialog box (an empty tile means "all values")
    
    (defun ssd (/ DynBlkPropValue ss blk name pop ret fuzz sel res)
      (vl-load-com)
      ;; DynBlkPropValue
      ;; Dialog box to choose dynamic properties values
      ;;
      ;; Argument : the dynamic properties list (vla-object list)
      (defun DynBlkPropValue (lst / tmp file pn av dcl_id val)
        (setq tmp  (vl-filename-mktemp "Tmp.dcl")
    	  file (open tmp "w")
        )
        (write-line
          (strcat
    	"DynBlkProps:dialog{label=\"Dynamic block filter\";"
    	":text{label=\"Block name: \""
    	(vl-prin1-to-string name)
    	";}spacer;:boxed_column{label=\"Dynamic properties\";"
          )
          file
        )
        (foreach p lst
          (setq pn (vla-get-PropertyName p))
          (cond
    	((setq av (vlax-get p 'AllowedValues))
    	 (setq pop
    		(cons (cons pn (cons "" (mapcar 'vl-princ-to-string av)))
    		      pop
    		)
    	 )
    	 (write-line
    	   (strcat
    	     ":popup_list{label="
    	     (vl-prin1-to-string pn)
    	     ";key="
    	     (vl-prin1-to-string pn)
    	     ";edit_width=25;allow_accept=true;}"
    	   )
    	   file
    	 )
    	)
    	((/= pn "Origin")
    	 (setq fuzz (cons pn fuzz))
    	 (write-line
    	   (strcat
    	     ":row{:edit_box{label="
    	     (vl-prin1-to-string pn)
    	     ";key="
    	     (vl-prin1-to-string pn)
    	     ";edit_width=12;allow_accept=true;}"
    	     ":edit_box{label=\"Fuzz\";key="
    	     (vl-prin1-to-string (strcat pn "_fuzz"))
    	     ";value=\"0.0\";edit_width=6;allow_accept=true;}}"
    	   )
    	   file
    	 )
    	)
          )
        )
        (write-line
          (strcat
    	"}spacer;:radio_row{key=\"selset\";"
    	":radio_button{label=\"All drawing\";key=\"all\";value=\"1\";}"
    	":radio_button{label=\"Selection\";key=\"sel\";}}"
    	"spacer;ok_cancel;}"
          )
          file
        )
        (close file)
        (setq dcl_id (load_dialog tmp))
        (if	(not (new_dialog "DynBlkProps" dcl_id))
          (exit)
        )
        (foreach p pop
          (start_list (car p))
          (mapcar 'add_list (cdr p))
          (end_list)
        )
        (action_tile
          "accept"
          "(foreach p (mapcar 'vla-get-PropertyName lst)
          (if (assoc p pop)
          (setq val (nth (atoi (get_tile p)) (cdr (assoc p pop))))
          (setq val (get_tile p)))
          (if (and val (/= val \"\"))
          (setq ret (cons (cons p val) ret))))
          (setq fuzz (mapcar (function (lambda (x)
          (cons x (get_tile (strcat x \"_fuzz\"))))) fuzz))
          (and (not ret) (setq ret T))
          (setq sel (get_tile \"selset\"))
          (done_dialog)"
        )
        (action_tile "cancel" "(setq ret nil)")
        (start_dialog)
        (unload_dialog dcl_id)
        (vl-file-delete tmp)
        ret
      )
      ;;----------------------------------------------------;;
      (and
        (or
          (and
    	(setq ss (cadr (ssgetfirst)))
    	(= 1 (sslength ss))
    	(setq blk (vlax-ename->vla-object (ssname ss 0)))
    	(sssetfirst nil nil)
          )
          (and
    	(sssetfirst nil nil)
    	(setq blk (car (entsel)))
    	(setq blk (vlax-ename->vla-object blk))
          )
        )
        (= (vla-get-ObjectName blk) "AcDbBlockReference")
        (= (vla-get-IsDynamicBlock blk) :vlax-true)
        (setq name (vla-get-EffectiveName blk))
        (DynBlkPropValue
          (vlax-invoke blk 'getDynamicBlockProperties)
        )
        (if	(= sel "all")
          (ssget "_X"
    	     (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*")))
          )
          (ssget (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*")))
          )
        )
        (setq res (ssadd))
        (vlax-for b	(setq ss (vla-get-ActiveSelectionSet
    			   (vla-get-activeDocument
    			     (vlax-get-acad-object)
    			   )
    			 )
    		)
          (if
    	(and
    	  (= (vla-get-EffectiveName b) name)
    	  (or
    	    (= ret T)
    	    ((lambda (lst)
    	       (apply
    		 '=
    		 (cons
    		   T
    		   (mapcar
    		     (function
    		       (lambda (p / n v l u f)
    			 (setq n (car p)
    			       l (assoc n lst)
    			       u (vla-get-UnitsType (caddr l))
    			 )
    			 (equal	(cond
    				  ((= 0 u) (cdr p))
    				  ((= 1 u) (angtof (cdr p)))
    				  (T (distof (cdr p)))
    				)
    				(cadr l)
    				(if (and (setq f (cdr (assoc n fuzz)))
    					 (numberp (read f))
    				    )
    				  (atof f)
    				  0.0
    				)
    			 )
    		       )
    		     )
    		     ret
    		   )
    		 )
    	       )
    	     )
    	      (mapcar
    		(function
    		  (lambda (p / n v)
    		    (list
    		      (setq n (vla-get-PropertyName p))
    		      (vlax-get p 'Value)
    		      p
    		    )
    		  )
    		)
    		(vlax-invoke b 'getDynamicBlockProperties)
    	      )
    	    )
    	  )
    	)
    	 (ssadd (vlax-vla-object->ename b) res)
          )
        )
        (vla-delete ss)
      )
      res
    )
    ;;; Calling function
    (defun c:ssd ()
      (sssetfirst nil (ssd))
      (princ)
    )
    Last edited by 'gile'; 2009-02-24 at 06:26 PM.

  5. #5
    Member
    Join Date
    2006-08
    Location
    Fairfax, VA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    Thank you so much for all the ideas! Next time I'm stuck, I'll have many more options to try.

    Tim, for what I'm trying to accomplish today, your solution is perfect.

    All of these are so intriguing that I'm tempted to go find more ways to use them.

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    Good to hear. You're welcome.

  7. #7
    Member
    Join Date
    2012-07
    Posts
    2
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    I would like to use your routine to create a button to select all blocks of my drawing, regardless of dynamic Properties, then I would withdraw from rotia the box that you used to set the parameters and leave only selecting all the same name blocks (dynamic with different Properties) is possible?

  8. #8
    Woo! Hoo! my 1st post
    Join Date
    2021-08
    Posts
    1
    Login to Give a bone
    0

    Default Re: Select all occurences of a Dynamic Block in Modelspace

    Quote Originally Posted by _gile View Post
    Hi,

    You can try this routine.
    SSD allows to select dynamic blocks according to their dynamic properties values

    Code:
    ;;; SSD R2.3 (gile) 14/07/2008
    ;;; Select dynamic blocks according to dynamic properties values
    ;;; Using:
    ;;; To make a selection, enter ssd at command prompt or,
    ;;; within a modification command, type (ssd) at "Select objects: " prompt
    ;;; Select a source dynamic block
    ;;; Choose properties values to filter in the dialog box (an empty tile means "all values")
    
    (defun ssd (/ DynBlkPropValue ss blk name pop ret fuzz sel res)
      (vl-load-com)
      ;; DynBlkPropValue
      ;; Dialog box to choose dynamic properties values
      ;;
      ;; Argument : the dynamic properties list (vla-object list)
      (defun DynBlkPropValue (lst / tmp file pn av dcl_id val)
        (setq tmp  (vl-filename-mktemp "Tmp.dcl")
    	  file (open tmp "w")
        )
        (write-line
          (strcat
    	"DynBlkProps:dialog{label=\"Dynamic block filter\";"
    	":text{label=\"Block name: \""
    	(vl-prin1-to-string name)
    	";}spacer;:boxed_column{label=\"Dynamic properties\";"
          )
          file
        )
        (foreach p lst
          (setq pn (vla-get-PropertyName p))
          (cond
    	((setq av (vlax-get p 'AllowedValues))
    	 (setq pop
    		(cons (cons pn (cons "" (mapcar 'vl-princ-to-string av)))
    		      pop
    		)
    	 )
    	 (write-line
    	   (strcat
    	     ":popup_list{label="
    	     (vl-prin1-to-string pn)
    	     ";key="
    	     (vl-prin1-to-string pn)
    	     ";edit_width=25;allow_accept=true;}"
    	   )
    	   file
    	 )
    	)
    	((/= pn "Origin")
    	 (setq fuzz (cons pn fuzz))
    	 (write-line
    	   (strcat
    	     ":row{:edit_box{label="
    	     (vl-prin1-to-string pn)
    	     ";key="
    	     (vl-prin1-to-string pn)
    	     ";edit_width=12;allow_accept=true;}"
    	     ":edit_box{label=\"Fuzz\";key="
    	     (vl-prin1-to-string (strcat pn "_fuzz"))
    	     ";value=\"0.0\";edit_width=6;allow_accept=true;}}"
    	   )
    	   file
    	 )
    	)
          )
        )
        (write-line
          (strcat
    	"}spacer;:radio_row{key=\"selset\";"
    	":radio_button{label=\"All drawing\";key=\"all\";value=\"1\";}"
    	":radio_button{label=\"Selection\";key=\"sel\";}}"
    	"spacer;ok_cancel;}"
          )
          file
        )
        (close file)
        (setq dcl_id (load_dialog tmp))
        (if	(not (new_dialog "DynBlkProps" dcl_id))
          (exit)
        )
        (foreach p pop
          (start_list (car p))
          (mapcar 'add_list (cdr p))
          (end_list)
        )
        (action_tile
          "accept"
          "(foreach p (mapcar 'vla-get-PropertyName lst)
          (if (assoc p pop)
          (setq val (nth (atoi (get_tile p)) (cdr (assoc p pop))))
          (setq val (get_tile p)))
          (if (and val (/= val \"\"))
          (setq ret (cons (cons p val) ret))))
          (setq fuzz (mapcar (function (lambda (x)
          (cons x (get_tile (strcat x \"_fuzz\"))))) fuzz))
          (and (not ret) (setq ret T))
          (setq sel (get_tile \"selset\"))
          (done_dialog)"
        )
        (action_tile "cancel" "(setq ret nil)")
        (start_dialog)
        (unload_dialog dcl_id)
        (vl-file-delete tmp)
        ret
      )
      ;;----------------------------------------------------;;
      (and
        (or
          (and
    	(setq ss (cadr (ssgetfirst)))
    	(= 1 (sslength ss))
    	(setq blk (vlax-ename->vla-object (ssname ss 0)))
    	(sssetfirst nil nil)
          )
          (and
    	(sssetfirst nil nil)
    	(setq blk (car (entsel)))
    	(setq blk (vlax-ename->vla-object blk))
          )
        )
        (= (vla-get-ObjectName blk) "AcDbBlockReference")
        (= (vla-get-IsDynamicBlock blk) :vlax-true)
        (setq name (vla-get-EffectiveName blk))
        (DynBlkPropValue
          (vlax-invoke blk 'getDynamicBlockProperties)
        )
        (if	(= sel "all")
          (ssget "_X"
    	     (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*")))
          )
          (ssget (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*")))
          )
        )
        (setq res (ssadd))
        (vlax-for b	(setq ss (vla-get-ActiveSelectionSet
    			   (vla-get-activeDocument
    			     (vlax-get-acad-object)
    			   )
    			 )
    		)
          (if
    	(and
    	  (= (vla-get-EffectiveName b) name)
    	  (or
    	    (= ret T)
    	    ((lambda (lst)
    	       (apply
    		 '=
    		 (cons
    		   T
    		   (mapcar
    		     (function
    		       (lambda (p / n v l u f)
    			 (setq n (car p)
    			       l (assoc n lst)
    			       u (vla-get-UnitsType (caddr l))
    			 )
    			 (equal	(cond
    				  ((= 0 u) (cdr p))
    				  ((= 1 u) (angtof (cdr p)))
    				  (T (distof (cdr p)))
    				)
    				(cadr l)
    				(if (and (setq f (cdr (assoc n fuzz)))
    					 (numberp (read f))
    				    )
    				  (atof f)
    				  0.0
    				)
    			 )
    		       )
    		     )
    		     ret
    		   )
    		 )
    	       )
    	     )
    	      (mapcar
    		(function
    		  (lambda (p / n v)
    		    (list
    		      (setq n (vla-get-PropertyName p))
    		      (vlax-get p 'Value)
    		      p
    		    )
    		  )
    		)
    		(vlax-invoke b 'getDynamicBlockProperties)
    	      )
    	    )
    	  )
    	)
    	 (ssadd (vlax-vla-object->ename b) res)
          )
        )
        (vla-delete ss)
      )
      res
    )
    ;;; Calling function
    (defun c:ssd ()
      (sssetfirst nil (ssd))
      (princ)
    )

    How do I correct this code so that a vertical scroll is displayed in the window if the dialog is not displayed?
    If the window is not displayed, the operation is aborted.
    Thank you in advance!

Similar Threads

  1. Select dynamic block and change to a different block
    By john.237249 in forum AutoLISP
    Replies: 0
    Last Post: 2012-03-05, 08:09 PM
  2. need to search for dynamic block attribute like quick select
    By USMCBody in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2010-07-01, 05:48 PM
  3. Unable to select Dynamic Block Handles / Grips
    By .chad in forum Dynamic Blocks - Technical
    Replies: 15
    Last Post: 2007-09-17, 01:54 PM
  4. Replies: 2
    Last Post: 2007-08-17, 09:16 AM
  5. Unable to select dimensions in Modelspace
    By rstiles in forum AutoCAD General
    Replies: 2
    Last Post: 2005-07-05, 11:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •