Jump to content
AChartier627

Modify attribute in nested dynamic block

Recommended Posts

AChartier627
Posted (edited)

Is there a way to modify attributes and/or custom parameters of a dynamic block that is nested within another dynamic block.

 

For example if I have a dynamic block named "elevator" which I can move up and down with a linear stretch parameter.

Within that block I have another dynamic block of a pneumatic cylinder named "cylinder" which I can change how far the central rod is extended with a second linear stretch parameter.

 

It is possible that I might have multiple versions of this block in the drawing.

 

Can I modify both the linear parameters using code similar to Lee Macs code below

 

;; http://www.lee-mac.com/dynamicblockfunctions.html ;;
;; 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 have not created the models yet because the answer to this question will determine how I build them.

 

Thanks in advance.

Edited by AChartier627

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

Yes it would be possible to programmatically manipulate the parameters of a dynamic block reference nested within the definition of another block in the same manner as you might for a primary block reference inserted into Modelspace (the block reference object being manipulated will merely have a different owner/container), since the Modelspace & Paperspace layouts themselves may be considered containers no different from a block definition.

 

Whether or not you should do this is another question...

Edited by Lee Mac

Share this post


Link to post
Share on other sites
AChartier627

Thank you for this encouraging answer.

 

I should have been more careful with my question and asked "how can it be done" rather than "can it be done".

 

I have never been able to use ssget with :N or :U or :V modifiers to be able to manipulate nested blocks.

 

I could use something like this to find the "elevator" blocks of maybe 3 types

 

    (setq sset (ssget "_A" '((0 . "INSERT")))); select all blocks on unfrozen layers
    (repeat (sslength  sset); repeat for the number of objects in the selection set
        (setq ename (ssname sset i)); selects each block sequentially
        (setq obj (vlax-ename->vla-object ename));  assigns the block entity to variable obj
        (setq effname (vla-get-EffectiveName (vlax-ename->vla-object ename))); Find the EffectiveName of the block
        (if
            (or
                (= effname "elevator1")
                (= effname "elevator2")
                (= effname "elevator3")
            );or
            (Do more stuff)
        );if
          (setq i (+ i 1)) ; sequences the counter
    );repeat 

 

I do not know how to cycle through the nested blocks within, for example elevator1 to find the nested block "cylinder" to allow me to change its attributes.

 

Any help would be gratefully accepted.

 

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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