How manipulate a dynamic block with lisp

How manipulate a dynamic block with lisp

Anonymous
Not applicable
1,195 Views
5 Replies
Message 1 of 6

How manipulate a dynamic block with lisp

Anonymous
Not applicable
Anybody out there try to insert then manipulate a dyno block with lisp -
where do I start ??
I would like to stretch & scale parts via lisp instead of manually on the
screen - more specifically
it would be cool if parts would stretch, flip, scale etc based on an
attributes' value or character
length whenever the attribute was edited. Ideas ??

Scott
0 Likes
1,196 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
You can use Tool Palettes to do this as you insert the block.
0 Likes
Message 3 of 6

Anonymous
Not applicable
Check out the routines in the file below...

;;
;;----------------------------------------------------------------------
; 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:fdblk (/ 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)
)

;;
;;----------------------------------------------------------------------
;;
0 Likes
Message 4 of 6

Anonymous
Not applicable
Scott

You have to dig a little deeper that with standard blocks but it's not hard. Attached is a few sample programs, posted here a few weeks ago by others, that read and alter dynamic blocks. I find it more intuitive if I name my block controls things like "Door Size" that the default "Distance1" or the like.

Ron
0 Likes
Message 5 of 6

Anonymous
Not applicable
Thanks guys - now I've got something to go on and it looks exciting to me !
"Scott McFarren" wrote in message
news:5135213@discussion.autodesk.com...
Anybody out there try to insert then manipulate a dyno block with lisp -
where do I start ??
I would like to stretch & scale parts via lisp instead of manually on the
screen - more specifically
it would be cool if parts would stretch, flip, scale etc based on an
attributes' value or character
length whenever the attribute was edited. Ideas ??

Scott
0 Likes
Message 6 of 6

Anonymous
Not applicable
thanks guys - you got me started and your suggestions have inspired me to
tackle
more code like this.

Scott

"Scott McFarren" wrote in message
news:5135213@discussion.autodesk.com...
Anybody out there try to insert then manipulate a dyno block with lisp -
where do I start ??
I would like to stretch & scale parts via lisp instead of manually on the
screen - more specifically
it would be cool if parts would stretch, flip, scale etc based on an
attributes' value or character
length whenever the attribute was edited. Ideas ??

Scott
0 Likes