Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting Flip State in a Dynamic Block with Lisp

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
RockyBrown4134
1305 Views, 4 Replies

Setting Flip State in a Dynamic Block with Lisp

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.

 

 

 

 

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
4 REPLIES 4
Message 2 of 5
Lee_Mac
in reply to: RockyBrown4134

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).

Message 3 of 5
RockyBrown4134
in reply to: Lee_Mac


@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.

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
Message 4 of 5
RockyBrown4134
in reply to: Lee_Mac

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.

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
Message 5 of 5
Lee_Mac
in reply to: RockyBrown4134

Excellent to hear - you're very welcome!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost