Is there an easy way to to set the flips state of a Dynamic Block?
I have attached the block.
I have tried Lee-Mac's "Toggle Dynamic Block Flip State" function but I dont know if I put it in the code in correctly.
Any Suggestions?
Thanks for your help in advance.
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
To toggle the flip-state of the block you could use:
(defun c:test ( / obj ) (if (and (setq obj (car (entsel "\nSelect dynamic block: "))) (= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj)))) (= :vlax-true (vla-get-isdynamicblock obj)) ) (LM:toggleflipstate obj) ) (princ) ) ;; Toggle Dynamic Block Flip State - Lee Mac ;; Toggles the Flip parameter if present in a supplied Dynamic Block. ;; blk - [vla] VLA Dynamic Block Reference object ;; Return: [int] New Flip Parameter value (defun LM:toggleflipstate ( blk ) (vl-some '(lambda ( prp / rtn ) (if (equal '(0 1) (vlax-get prp 'allowedvalues)) (progn (vla-put-value prp (vlax-make-variant (setq rtn (- 1 (vlax-get prp 'value))) vlax-vbinteger)) rtn ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) (vl-load-com) (princ)
Toggle Flip State function from here.
Alternatively, to set the Flip State to a specific value, you could use my Set Dynamic Block Property Value function, e.g.:
(defun c:test ( / obj ) (if (and (setq obj (car (entsel "\nSelect dynamic block: "))) (= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj)))) (= :vlax-true (vla-get-isdynamicblock obj)) ) (LM:setdynpropvalue obj "hrflip" 1) ) (princ) ) ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) (vl-load-com) (princ)
Using a value of either 1 (flipped) or 0 (unflipped).
@Lee_Mac wrote:
(defun c:test ( / obj )
(if (and (setq obj (car (entsel "\nSelect dynamic block: ")))
(= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))))
(= :vlax-true (vla-get-isdynamicblock obj))
)
(LM:setdynpropvalue obj "hrflip" 1)
)
(princ)
)
Thanks. I like the "LM:setdynpropvalue " better.
Can "entsel "\nSelect dynamic block:" be changed to ENTLAST to get the last entity inserted instead of selecting an entity?
My thought process is to insert the block, then turn back aroun and select the block, and set the flip state. Unless theres another way of doing it.
Here is what I did:
(defun c:test ( / obj )
; (if (and (setq obj (car (entsel "\nSelect dynamic block: ")))
(if (and (setq obj (entlast))
(= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))))
(= :vlax-true (vla-get-isdynamicblock obj))
)
(LM:setdynpropvalue obj "hrflip" 1)
)
(princ)
)
I changed the line of code to Select the Last Entity and it works great.
Thanks for the help.
Excellent to hear - you're very welcome!