set distance by lisp in a dynamic block

set distance by lisp in a dynamic block

R0m3r014
Contributor Contributor
3,166 Views
8 Replies
Message 1 of 9

set distance by lisp in a dynamic block

R0m3r014
Contributor
Contributor

Hi.
Maybe someone here in this forum can help me.
I'm trying to set the distance for a dynamic block of a single parameter; which is linear and is called Distance1.
I do not know what I'm doing wrong, but I can not do it and change the desired distance.
He helped me with the functions of Lee Mac, but something is wrong. Any help very similar, I will be completely grateful.

(defun c: ddd (/ obj dd)     (if (y (setq obj (car (entsel "\ ndynamic block:")              (setq dd (getdist "\ Length:"))))              (= "AcDbBlockReference" (vla- get-objectname (setq obj (vlax-esame-> vla-object obj))))              (=: vlax-true (vla-get-isdynamicblock obj))         )         (LM: setdynpropvalue obj "Distance1" dd)     )     (princ) )


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

 

0 Likes
Accepted solutions (2)
3,167 Views
8 Replies
Replies (8)
Message 2 of 9

Satish_Rajdev
Advocate
Advocate
Accepted solution

There are so many mistake in your code so I wrote new one, Give a try on this:

(defun c:ddd ( / d o)
  (if (and (setq o (car (entsel "\nSelect Dynamic Block : ")))
	   (setq o (vlax-ename->vla-object o))
	   (if (not (eq (vla-get-objectname o) "AcDbBlockReference"))
	     (alert "Please select block object.")
	     t
	   )
	   (if (not (eq (vla-get-isdynamicblock o) :vlax-true))
	     (alert "Please select dynamic block.")
	     t
	   )
	   (setq d (getdist "\nSpecify Length : "))
      )
    (LM:setdynpropvalue o "Distance1" (rtos d 2 2))
  )
  (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)

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 3 of 9

_gile
Consultant
Consultant

Hi,

 

The simplest way to get or set dynamic properties is using the getpropertyvalue and setpropertyvalue functions. See >>this reply<< to a recent topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 9

R0m3r014
Contributor
Contributor

It really works. Thank you very much for the quick answer. regards

0 Likes
Message 5 of 9

R0m3r014
Contributor
Contributor

@Satish_Rajdev 

That works very well
I just wish I could have a multiple selection of blocks in a selection set.

How can I achieve it?

I appreciate your appreciable help.

0 Likes
Message 6 of 9

_gile
Consultant
Consultant

@R0m3r014 wrote:

I just wish I could have a multiple selection of blocks in a selection set.

How can I achieve it?


Try this:

 

(defun c:ddd (/ ss dist i br)
  (if
    (and
      (setq ss (ssget '((0 . "INSERT"))))
      (setq dist (getdist "\nDistance: "))
    )
     (repeat (setq i (sslength ss))
       (setq br (ssname ss (setq i (1- i))))
       (if (= (getpropertyvalue br "IsDynamicBlock") 1)
         (vl-catch-all-apply
           'setpropertyvalue
           (list br "AcDbDynBlockPropertyDistance" dist)
         )
       )
     )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 9

R0m3r014
Contributor
Contributor

@_gile

your code works for the selection of multiple dynamic blocks.
however, when entering the length, the changes in said dynamic blocks are not applied.

the parameter is still Distance1.

What could be failing?

0 Likes
Message 8 of 9

_gile
Consultant
Consultant
Accepted solution

Oopss!...

Just replace:

(list br "AcDbDynBlockPropertyDistance" dist)

with:

(list br "AcDbDynBlockPropertyDistance1" dist)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 9

R0m3r014
Contributor
Contributor

@_gile  That really is what I needed. Thank you very much for your valuable time and support. regards

0 Likes