Set dynamic block property value upon insert

Set dynamic block property value upon insert

Anonymous
Not applicable
2,044 Views
5 Replies
Message 1 of 6

Set dynamic block property value upon insert

Anonymous
Not applicable

Hello everyone Smiley Happy

 

Found LM's dynamic block functions but I can't incorporate the simplest task I want to accomplish. The dynamic block has 3 parameters

e.g.

par1 = 5' 4"

par2 = 45

par3 = 1/2"

 

I need help to insert the block and instantly modify the parameters through lisp. Please help, Thanks in advance! Smiley Happy

 

(defun c:insertBLK ()
(command ".-insert" "C:\\myblock.dwg" pause 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)
    )
)

;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

 

 

0 Likes
Accepted solutions (1)
2,045 Views
5 Replies
Replies (5)
Message 2 of 6

Shneuph
Collaborator
Collaborator
Accepted solution

This worked for one of my dynamic blocks.  No changes to LM's functions:

(defun c:insertBLK ()
  (command ".-insert" "detail callout.dwg" pause 1 "" "")
  (LM:setdynpropvalue (vlax-ename->vla-object (entlast)) "Visibility" "Section")
  (princ)
  );defun
---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the reply Shneuph this will get me going.

 

Only weird thing is when I set angle parameter to "45" it set it to 58.31 in the drawing.

0 Likes
Message 4 of 6

Shneuph
Collaborator
Collaborator

It needs Radians.. You can use CVUNIT function to easily convert.  You essentially told it the angle to use was (edit: 45 radians which is):2578.31 degrees.  Which when you cancel out all the full circles comes out to 58.31 degrees left over.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 5 of 6

Anonymous
Not applicable
I could've NOT guessed that at all! lol
I'm ok just to use radian (0.785398), Thanks again Shneuph!
0 Likes
Message 6 of 6

Shneuph
Collaborator
Collaborator

Always glad to help when I can.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes