Set Value in Dynamic Block

Set Value in Dynamic Block

david.faunce
Enthusiast Enthusiast
1,589 Views
3 Replies
Message 1 of 4

Set Value in Dynamic Block

david.faunce
Enthusiast
Enthusiast

(USING AUTOCAD ELECTRICAL 2017)

 

I'm using Lee Mac's LISP function to change the value of the dynamic block. I can't seem to get this working.

 

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

 

** I would love to be able to get the block by entity name (IE: do not have the user select it - the entity is already known) **

IS THIS POSSIBLE???

 

 

But just to see if I can get this working, I went ahead and used entsel to have the user select the block (ideally, I won't want the user to select anything)

I've tried to run this by using the following commands:

(setq blk (car (entsel)))
(LM:setdynpropvalue (blk "Visibility1" "1 inch WC")

But I get the error:

bad argument type: VLA-OBJECT <Entity name: 4868b70>

 

What do I need to enter to get this function working?

 

lisp_error.jpg

 

 

 

 

0 Likes
Accepted solutions (1)
1,590 Views
3 Replies
Replies (3)
Message 2 of 4

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try with vla-object instead of ename

(setq blk (car (entsel)))
(LM:setdynpropvalue ((vlax-ename->vla-object blk) "Visibility1" "1 inch WC")
Message 3 of 4

david.faunce
Enthusiast
Enthusiast

Thanks again Ranjit!

 

Do you know how I can set the blk variable if I already know the handle entity?

 

ie:   (setq  blk   ** handle entity = "1C43" **)

 

??

0 Likes
Message 4 of 4

david.faunce
Enthusiast
Enthusiast

Nevermind. I got it.

 

(setq blk (vlax-ename->vla-object (handent "1C43")))
(LM:setdynpropvalue blk "Visibility1" "1 inch WC")

 

0 Likes