Jump to content

how to change existing Dynamic block property


Recommended Posts

Posted

Hello Friends,

 

I want to change property value of existing dynamic block. I am new to this language so, please help me with it. 

Posted (edited)

You can make use of my library of Dynamic Block Functions; there are plentiful examples on the web of these functions being used in other programs that you can use to learn from.

Edited by Lee Mac
Posted

Ok thanks for quick reply Lee. I will check that

Posted

Hello Lee,

 

Am I using it right ? Seriously I am newbee I dont know how to program in Autolisp.

 

 

(defun c:dynamo (/ lst obj sel)
          (setq ssl (ssget "x" '((0 . "INSERT") (-4 . "<not") (410 . "model") (-4 . "not>"))));setq
       ;(while 
       (/= (sslength ssl) 0)
       (setq sslfi (ssname ssl 0))
       (setq sslx (cdr (assoc 2 (entget sslfi))))
       ; (if (vl-string-search "*" sslx)
       (setq obj (vlax-ename->vla-object sslfi))
       (vlax-property-available-p obj 'IsDynamicBlock)
       (eq (vla-get-IsDynamicBlock obj) :vlax-true)
           ;);while
      
    (progn
      (foreach p (vlax-safearray->list
           (vlax-variant-value (vla-getdynamicblockproperties obj))
         )
    (if (and (setq a (vlax-get p 'PropertyName))
         (setq b (vlax-get p 'AllowedValues))
        );and
      (setq lst (cons (list a b) lst))
    );if
      );foreach
      (if lst
    (princ lst)
      );if
    );progn
(setq val (getstring "\n Enter the desired value"))
(LM:setdynpropvalue ( b a val))
  (princ)
);defun
(princ)

 

 

(defun LM:setdynpropvalue ( obj p val )
    (setq p (strcase p))
    (vl-some
       '(lambda ( x )
            (if (= p (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 obj 'getdynamicblockproperties)
    )
)

Posted

Not quite - there are two elements that you first need to ascertain: the name of the dynamic block parameter that you need to change, and the data type of the parameter value (so that you can prompt the user for the appropriate data).

 

Once you have this information, you can use a program such as the following to set the parameter value (you will need to adjust the property name and user prompt to suit the above):

(defun c:dynamo2 ( / i o p s v )

    (setq p "YourPropertyName")
    
    (cond
        (   (not (setq s (ssget "_X" '((0 . "INSERT") (410 . "~Model")))))
            (princ "\nNo blocks found in Paperspace.")
        )
        (   (/= "" (setq v (getstring "\nEnter the desired value: ")))
            (repeat (setq i (sslength s))
                (setq i (1- i)
                      o (vlax-ename->vla-object (ssname s i))
                )
                (if (= :vlax-true (vla-get-isdynamicblock o))
                    (LM:setdynpropvalue o p v)
                )
            )
        )
    )
    (princ)
)
(vl-load-com)

There is no need to modify the code for my functions in any way, and I would also prefer if you retained the code headers.

  • Like 1
Posted

Thank you very much LEE, you are genius.How can I use it on batch files?

Posted

Hello Lee,

 

Please start your youtube channel too to provide Autolisp tutorials. So, newbees like me can get to know Autolisp clearly.

  • 4 years later...
Posted

When a user needs to put in the desired value. What would be a good choice to give the user an option to either (Square Feet or Acres) as input?

 

        (   (/= "" (setq v (getstring "\nEnter the desired value: ")))

 

 

Thanks for the help.

Posted (edited)

Various ways here are 3

 

use Initget 

(initget 1 "Sqft or Acres")
  (setq ans (getkword "\nEnter Sqft or Acres"))
  (if (= ans "Arces")(do something))

 

Getstring

(if (= v nil)(setq v "Acres"))
(setq vans (getstring (strcat "\nEnter the desired value: " v)))
(if (= vans nil)
(princ)
(setq v vans)
)

; disadvantage can enter anything
; advantage is can press Enter for default 

A user library dcl for input replacement for Initget

image.png.8cf1cef3d4365601113fc3f044d4998a.png

Edited by BIGAL
Posted

Thank you! Let me see what I can put together.

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