Jump to content

Dynamic block x Autolisp


FabioDG

Recommended Posts

Impressive, I suspect that this is exactly what needed.

But as I do not understand anything VisualLISP not know how to use it.

Using their routines, below is what I tried to do to set to "1" the value of a label distance of a dynamic block.

Of course it is not working.

 


(defun c:test ( blk prp val )
  (setq blk (car (entsel)))    ; block name
  (setq prp "distance1")      ; label distance
  (setq val 1)                     ; distance value
  (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)
   )

)

 

Thank you.

Edited by FabioDG
Link to comment
Share on other sites

There are some things wrong about your code, I rewrite it and it's fine.

(defun c:test (/ blk prp val)
 (setq blk (vlax-ename->vla-object (car (entsel))))		; block object
 (setq prp "distance1")		; label distance
 (setq val 1)				; distance value

 (setq prp (strcase prp))
 (vl-some
   '(lambda (x)
      (if (= prp (strcase (vla-get-propertyname x)))
   (vla-put-value  x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
      )
    )
   (vlax-invoke blk 'getdynamicblockproperties)
 )
)

Link to comment
Share on other sites

Please note that there is no need to modify my code in any way -

You should call the function with the required arguments, e.g.:

(defun c:test ( / blk )
   (if (and (setq blk (car (entsel "\nSelect dynamic block: ")))
            (setq blk (vlax-ename->vla-object blk))
            (= "AcDbBlockReference" (vla-get-objectname blk))
            (= :vlax-true (vla-get-isdynamicblock blk))
       )
       (LM:setdynpropvalue blk "distance1" 1.0)
   )
   (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)

I would appreciate if you retained my code headers when using my code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...