Changing dynamic Block value from model space

Changing dynamic Block value from model space

thomas_schluesselberger
Advocate Advocate
2,619 Views
29 Replies
Message 1 of 30

Changing dynamic Block value from model space

thomas_schluesselberger
Advocate
Advocate

Hi!

 

Following situation:

I have multible layouts and in each there is a dynamic block.

The dynamic block contains visiblity states and lookups.

 

I want to be able to change the values of the parameters from model-space. So i don't need to go inside the layouts one by one.

I also need to select in which layouts the changes should be made. (i dont want the changes in each layout)

 

 

I attached you my block and copied it in some layouts.

 

Maybe someone has some ideas.

 

Thanks!

0 Likes
2,620 Views
29 Replies
Replies (29)
Message 2 of 30

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

If the reason you want this is because of the time it takes to switch layouts, then i would think of another solution..

Like turning some viewports off than switch layout.

 

Moshe

0 Likes
Message 3 of 30

Sea-Haven
Mentor
Mentor

It can be done, just not sure how much faster it is going to be by the time you enter layout name and the correct visibilty required for the 2 entries. Compare that to just going to next layout and changing. 

 

Any way get a copy of Lee-Mac.com dynamic block properties lisp it has the code to change visibilty. 

 

I have used Lee's code and yes could do some form of dcl enter layout by number simplest way and have the visibility displayed as a choice for the 2 properties.

 

Some sample code, needs a custom dcl with layout number and 2 radio button columns. Hint multi radio buttons 2 col.lsp

 

;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)

(defun insdynv (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(setq pt (getpoint "\nPick a pt for block "))
(command "-insert" blkname "s" 1.0  pt 0)
(setq obj (vlax-ename->vla-object (entlast)))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)

; set existing block visibilty

(defun insdyne (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq obj (vlax-ename->vla-object (car (entsel "\nPick a dynamic block "))))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)
0 Likes
Message 4 of 30

thomas_schluesselberger
Advocate
Advocate

Hi


Thank you for your answers.

 

Unfortunately, as suggested by @Moshe-A, I can't control it with viewports.

 

I would have considered that the input, in which layouts the blocks should get adjusted, works kinda like the LISP "TabSort" from LeeMac. There a window pops up and I can simply select the desired layouts while holding down the CTRL key. And then I can select which visibility should be activated by selecting buttons. I think i could save a lot of time with this method.

 

Unfortunately, due to my limited lisp skills, i don't understand anything from the code you've sent.

 

 

0 Likes
Message 5 of 30

Moshe-A
Mentor
Mentor

@thomas_schluesselberger  hi,

 

i saw your sample drawing and it's does not contain any viewports (and you did not answer directly to my question) so i do not see what's the difficulty to switch layouts.

 

Moshe

 

 

 

0 Likes
Message 6 of 30

thomas_schluesselberger
Advocate
Advocate
I thought that I should use viewports instead of the block.
But the block serves partly to overwrite the frames of the existing viewports.

And the problem with changing the layout is that I have a lot of layouts. I have to switch it back and forth quite often, which is why it becomes very time-consuming at some point
0 Likes
Message 7 of 30

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

Sorry mate, i encountered issues with your blocks German name (i'm holding only english version)

also there is inside "origin" property that is not seen.

 

bottom line: only one with AutoCAD German version can help here.

 

Moshe

 

 

0 Likes
Message 8 of 30

Sea-Haven
Mentor
Mentor

Getting somewhere slowly, in your block is 3 visibilty states. I have shown only 2 as choices.

SeaHaven_0-1684647232415.png

I need to add a layout name list box also. Is this something like what your looking for ?

 

I have a 3 column version but it is limited to about 20 buttons but could be used for pick layout name.

 

 

0 Likes
Message 9 of 30

thomas_schluesselberger
Advocate
Advocate

Hi!

 

Yes that's what i'm looking for.

 

And am i understanding you wright? The 20 button limit means when i have e.g. 25 layouts, i can only edit 20?

It's not that often that I have over 20 layouts, but if I did, it wouldn't be that great.

 

 

Thank you allready.

 

0 Likes
Message 10 of 30

Sea-Haven
Mentor
Mentor

The dcl buttons are limited to screen size, around 20, a list box has like a 256 limit. 

 

Using lee-mac's great code only gets the 1st Visibilty name so had to look at new code that gets the visibility names in this case there are 2 "Breite", "Prüflegende", there is a 3rd "Origin" but I ignored that one. Its a work in progress. Getting the visibility to work 1st. Hopefully soon. I have to change my Multi radio 3 cols to have a list box as 1st select that is a seperate task as it will be a custom dcl, compared to my existing multi library code. Need a day maybe 2.

 

 

 

 

0 Likes
Message 11 of 30

thomas_schluesselberger
Advocate
Advocate

Ok, take your time 🙂

0 Likes
Message 12 of 30

Sea-Haven
Mentor
Mentor

Getting there this is step one, go to a layout and run the lisp. Make sure Multi Radio buttons 2 col.lsp is saved in a support path directory or add correct directory to the Load.

 

(defun c:dblvis ( / blkdyn bprop lst visname lst1 lst2 lst3 ans1 ans2)

;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; 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 Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of ((<prop> . <value>) ... )

(defun LM:getdynprops ( blk )
    (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)
;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

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

(setq blkdyn (vlax-ename->vla-object (car  (entsel "Pick dynamic blk"))))

(setq bprop (LM:GETDYNPROPS blkdyn))

(setq lst '())
(foreach visname bprop
  (if (= (car visname) "Origin")
   (princ "miss")
   (setq lst (cons (car visname) lst))
  )
)

(setq lst1 (LM:getdynpropallowedvalues  blkdyn (nth 0 lst)))
(setq lst2 (LM:getdynpropallowedvalues  blkdyn (nth 1 lst)))
(setq lst3 (LM:getdynpropallowedvalues  blkdyn (nth 2 lst)))

(setq lst1 (cons "please select " lst1))
(setq lst3 (cons "please select " lst3))

(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))

(AH:BUTTSCOL 1 1 "Select visibilty" lst1 lst3)
(setq ans1 (nth ah:2col lst1))
(setq ans2 (nth ah:2col2 lst3))

(LM:setdynpropvalue blkdyn (nth 0 lst) ans1)
(LM:setdynpropvalue blkdyn (nth 2 lst) ans2)

(command "regen")
(princ)
)

 

The next step is find your block in a layout give its name.

Final step is add the list box select a layout to the 2col dcl. 

 

 

 

0 Likes
Message 13 of 30

thomas_schluesselberger
Advocate
Advocate

Hello,

 

sorry for the late reply, I didn't get a notification about your anwser.

I tested it, but can't get it to work.

 

Where can i find "Multi Radio buttons 2 col.lsp" ?

 

I don't quite understand that either:

The next step is find your block in a layout give its name.

Final step is add the list box select a layout to the 2col dcl. 

 

Maybe you can describe it to me a bit more how to get the LISP to work.

 

0 Likes
Message 14 of 30

Sea-Haven
Mentor
Mentor

My bad forgot to attach sorry. See below.

 

The program makes a dcl on the fly based on the information pulled from your dynamic block.

 

It needs to be saved in a directory that is set to a support path Options Files Support. Or add the location where you have saved it to the  (load "c:\\mylisps\\Multi Radio buttons 2 col.lsp") etc your directory where you saved it, note the use of "\\" 

 

It should display same as image above.

 

0 Likes
Message 15 of 30

thomas_schluesselberger
Advocate
Advocate

Hi,

 

i tested it and it kinda works.

But there is a problem if you choose the default values ("Standard" and "Aus"). It doesn't change to this values.

Only when you first select another option and then go back to these two.

 

The other options are working really nice and the display looks good.

 

Whats left is just the small bugfix and the option to choose the wanted layouts.

 

 

0 Likes
Message 16 of 30

Sea-Haven
Mentor
Mentor

Ok will look at adding the select a layout to the dcl. I will check on the updating not working. 

0 Likes
Message 17 of 30

Sea-Haven
Mentor
Mentor

I have duplicated your problem, it was part of the radio 2col buttons code not resetting properly. Use version attached.

 

The wheels turn slowly sometimes still debugging.

SeaHaven_0-1685953035087.png

Try this pick a layout name have to fix that.

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-dynamic-block-value-from-model-space/td-p/11969710
; ver 1 posted 26-05-2023

(defun c:dblvis ( / blkdyn bprop lst visname lst1 lst2 lst3 ans1 ans2)

;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; 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 Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of ((<prop> . <value>) ... )

(defun LM:getdynprops ( blk )
    (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)
;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

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

(setq blkdyn (vlax-ename->vla-object (car  (entsel "Pick dynamic blk"))))
(setq bname (vla-get-effectivename blkdyn))
(setq bprop (LM:GETDYNPROPS blkdyn))

(setq lst '())
(foreach visname bprop
  (if (= (car visname) "Origin")
   (princ "miss")
   (setq lst (cons (car visname) lst))
  )
)

(setq lst1 (LM:getdynpropallowedvalues  blkdyn (nth 0 lst)))
(setq lst2 (LM:getdynpropallowedvalues  blkdyn (nth 1 lst)))
(setq lst3 (LM:getdynpropallowedvalues  blkdyn (nth 2 lst)))

; add please choose
(setq lst1 (cons "please select " lst1))
(setq lst3 (cons "please select " lst3))

(if (not AHlist2col)(load "List plus radio buttons 2col.lsp"))
(setq lays (layoutlist))

(AHlist2col 1 1 "Select visibilty" lst1 lst3 lays)
(setq ans1 (nth ah:2col lst1))
(setq ans2 (nth ah:2col2 lst3))
(if (= laynum nil)(setq laynum "0"))

(setq tabn (nth (atoi laynum) lays))
(setvar 'ctab tabn)
(setq ss (ssget "X" (list (cons 0 "INSERT")(CONS 2 "*U*")(cons 410 tabn))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
(if (= (vla-get-effectivename obj) bname)
(progn
(LM:setdynpropvalue obj (nth 0 lst) ans1)
(LM:setdynpropvalue obj (nth 2 lst) ans2)
)
)
)
(command "regen")
(princ)
)

 

 

 

0 Likes
Message 18 of 30

thomas_schluesselberger
Advocate
Advocate

Hi,

 

thanks for your work!

I tested, but sadly got some problems:

 

- The layer list is cut off so i can't read the layout names. Maybe you can make the width of the layer window bigger.

thomas_schlssi_0-1686030700119.png

- The Layer list sorts it self alphabetical, maybe it's possible to sort the layers the same way as in the layer tabs.

- Currently i need to select the block manually. Is it possible to change that, so it always uses 

    "_emc_Planlayout_Prüflegende"? (i want to use the LISP from the model-space)

- When trying to change some values with the right layout selected, it doesn't change anything.

- Currently i can only select one layout, i need to be able to select multible layouts and apply the changes to all of the selected.

 

 

0 Likes
Message 19 of 30

Sea-Haven
Mentor
Mentor

Ok

- The Layer list sorts it self alphabetical, maybe it's possible to sort the layers the same way as in the layer tabs. Not sure. A quick and dirty may be add x- to each layout name 1-lay1, 2-lay34 etc Its only used for display not actaul name as the item selected number is returned.

 

- Currently I need to select the block manually. Can be done requires a bit of coding as dynamic block becomes anonymous name. But no need to select a block that was done as a more global approach, so can just fill in lst1 & lst2 with known values.

 

- When trying to change some values with the right layout selected, it doesn't change anything. Will check was working correctly.

 

- Currently I can only select one layout, lets look at that as version 3. In the list box there is a switch that can be set and you can select more than 1.

 

 

0 Likes
Message 20 of 30

thomas_schluesselberger
Advocate
Advocate
You got any new improvements? 🙂
0 Likes