;;Dynamic block functions - Allen Johnson
;;
;;------------------------------------------------- ---------------------
; shows what variables there are in your block
(defun c:tdb ()
(setq obj (vlax-ename->vla-object (car (entsel))))
(if (= (vlax-get-property obj 'isdynamicblock) :vlax-true)
(progn
(setq v (vla-getdynamicblockproperties obj))
(setq vval (vlax-variant-value v))
(setq sal (vlax-safearray->list vval))
(setq salnth (length sal))
(setq count 0)
(while (/= count salnth)
(vlax-dump-object (nth count sal))
(setq count (+ count 1))
)
)
(print "Not a dynamic block")
)
(setq count nil)
(princ)
)
;;
;;----------------------------------------------- -----------------------
;; changes a given variable in your block
(defun chgdynprop (e propname newval / obj v vval sal tot i)
(setq obj (if (= (type e) 'vla-object) e (vlax-ename->vla-object e)))
(if (= (vlax-get-property obj 'isdynamicblock) :vlax-true)
(progn
(setq v (vla-getdynamicblockproperties obj)
vval (vlax-variant-value v)
sal (vlax-safearray->list vval)
tot (length sal)
i 0
)
(while (< i tot)
(if (= (vlax-get-property (nth i sal) "PropertyName") propname)
(progn
(vlax-put-property (nth i sal) "Value" newval)
(setq i tot)
)
(setq i (1+ i))
)
)
)
)
)
;;
;;--------------------------------------------------------- -------------
;; reads a given variable in your block
(defun getdynprop (e propname / obj v vval sal tot i curval)
(setq obj (if (= (type e) 'vla-object) e (vlax-ename->vla-object e)))
(if (= (vlax-get-property obj 'isdynamicblock) :vlax-true)
(progn
(setq v (vla-getdynamicblockproperties obj)
vval (vlax-variant-value v)
sal (vlax-safearray->list vval)
tot (length sal)
i 0
)
(while (< i tot)
(if (= (vlax-get-property (nth i sal) "PropertyName") propname)
(progn (setq curval (vlax-get-property (nth i sal) "Value")) (setq i tot))
(setq i (1+ i))
)
)
)
)
(if curval (vlax-variant-value curval))
)
;;
;;------------------------------------------ ----------------------------
;; returns a selection set of blocks with the same effectivename
;; example use:
;; (setq dbselset (ssdblk "MyDynBlockName"))
;;
(defun ssdblk (effname / ssx ssf c en)
(setq ssx (ssget "_X" (list (cons 2 (strcat effname ",`*U*")))))
(setq ssf (ssadd)
c 0
)
(if ssx
(repeat (sslength ssx)
(setq en (ssname ssx c)
c (1+ c)
)
(if (= (print (vla-get-effectivename (vlax-ename->vla-object en))) effname)
(ssadd en ssf)
)
)
)
ssf
)
;;
;;--------------------------------------------------- -------------------
;;
;; find dynamick blocks
;; a command line function to select all dynamic blocks
;; with the same "effectivename"
(defun c:fdb (/ en obj effname)
(setq en (car (entsel)))
(if en
(progn (setq obj (vlax-ename->vla-object en))
(if (vlax-property-available-p obj 'effectivename)
(progn (setq effname (vlax-get-property obj "effectivename"))
(command "_Select" (ssdblk effname))
)
(prompt "\nNot a block.\n")
)
)
)
(princ)
)
;;
;;--------------------------------------------------- -------------------
;;
;sample - set/change visibility:
;
;(command "_-Insert" shapename ipt 1 1 0)
;(setq obj (entlast))
;(chgdynprop obj "BeamSizes" "Beam99")
;(entupd obj)
;
;where "BeamSizes" is the name of a visibility state and "Beam99" one of the visibility state names