After about a couple months of messing with Lisp codes that users have been sending me. I'm pretty happy with this one. Taking this code, and placing it in my Lisp toolbox allows me to call it from many other Lisp codes. Tremendously opening the door to more uses of Dynamic Blocks. Before we would use a lot of (ENTMAKE's to create custom blocks. The code is relatively simply to manipulate Dynamic blocks by simply getting a selection set. Then modifying the bottom portion of the Dynamic block code for the parameter and what you want it to be set to.
Here is the code. Don't get scared if you're new to LISP because only the bottom line is what needs to be modified.
(defun myModifyBk ( lstProp / ss index cnt oBkRef oProps i j oSBReferenceProperty)
(vl-load-com)
(SETQ ss (SSGET "L"))
(setq index 0
cnt (sslength ss)
)
(while (< index cnt)
(setq e (ssname ss index))
(setq oBkRef (vlax-ename->vla-object e))
(setq oProps (vlax-variant-value (vla-GetDynamicBlockProperties oBkRef)))
(setq i (vlax-safearray-get-l-bound oProps 1))
(while (<= i (vlax-safearray-get-u-bound oProps 1))
(setq oSBReferenceProperty (vlax-safearray-get-element oProps i))
(print (strcat (vla-get-PropertyName oSBReferenceProperty) "="))
(princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
(setq i (1+ i))
)
(setq j 0)
(while (< j (length lstProp))
(setq sProp (strcase (nth j lstProp)))
(setPropValue oProps sProp (nth (+ 1 j) lstProp))
(setq j (+ 2 j))
) ;while < j (length lstProp)
(setq index (1+ index))
) ;while < index cnt
(princ)
)
(defun setPropValue (oProps sProp Val / i oSBReferenceProperty sPName iFound)
(setq i (vlax-safearray-get-l-bound oProps 1))
(setq iFound 0)
(while (and (<= i (vlax-safearray-get-u-bound oProps 1)) (= iFound 0))
(setq oSBReferenceProperty (vlax-safearray-get-element oProps i))
(setq sPName (vla-get-PropertyName oSBReferenceProperty))
(if (= (strcase sPName) sProp)
(progn
(print (strcat "Old value of " sPName "="))
(princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
(vla-put-value oSBReferenceProperty
(vlax-make-variant Val
(vlax-variant-type (vla-get-value oSBReferenceProperty))
)
)
(print "New value=")
(princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
(setq iFound 1)
)
)
(setq i (1+ i))
)
(princ)
)
;;;;DTR converts degrees to radians.
(defun dtr (a)
(* pi (/ a 180.0))
)
;;RTD converts radians to degrees.
(defun rtd (a)
(/ (* a 180.0) pi)
)
;;The section below is the portion to modify to manipulate your dynamic block afte ryou establish a selection set.
(myModifyBk (list "DynamicBlockParmatername" DynamicBlockValue))
Hope this helps everyone with getting their Dynamic blocks into some custom LISP codes.
Click here to download the LISP file:Download Dblockcode.lsp