Changing dynamic Block value from model space

Changing dynamic Block value from model space

thomas_schluesselberger
Advocate Advocate
2,663 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,664 Views
29 Replies
Replies (29)
Message 21 of 30

Sea-Haven
Mentor
Mentor

Oops fell off the Todo list. Top of the list now.

0 Likes
Message 22 of 30

Sea-Haven
Mentor
Mentor

Ok try this, getting there.

 

Layout names now 40 characters.

Layout list matches the layout names order.

Uses block name.

Changes correct layout values, if no layout selected will update 1st in list.

 

Select more than 1 layout next version.

 

; 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
; ver2 posted 19-06-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)
    )
)

; need to use this block "_emc_Planlayout_Prüflegende"
(command "-insert" "_emc_Planlayout_Prüflegende" '(0 0 0) 1 1 0)
(setq ent (entlast))
(setq blkdyn (vlax-ename->vla-object ent))
(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 AHlist2col)(load "List plus radio buttons 2col.lsp"))

(setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(setq laylst '())
(vlax-for layn alllayouts
(setq laylst (cons (list (vla-get-taborder layn) (vla-get-name layn)) laylst))
)
(setq laylst (vl-sort laylst '(lambda (x y) (< (car x)(car y)))))
(setq lays '())
(foreach layn laylst
(if (= (cadr layn) "Model")
(princ)
(setq lays (cons (cadr layn) lays))
)
)
(setq lays (reverse lays))


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

(entdel ent)
;(setvar 'ctab layname)
; choose block in ctab
(if (= layname nil)(setq layname (car lays)))
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "*u**")(cons 410 layname))))
(setq blkdyn (vlax-ename->vla-object (ssname ss 0)))

(If (=  (vlax-get  blkdyn 'effectivename) "_emc_Planlayout_Prüflegende")
(progn
  (LM:setdynpropvalue blkdyn (nth 0 lst) ans1)
  (LM:setdynpropvalue blkdyn (nth 2 lst) ans2)
)
)

(command "regen")
(princ)
)

 

; List select and 2 radio butoon columns.
; By alan H June 2030 

(defun col1 ( / l)
(setq x 1)
(repeat (length ah:butlst)
    (setq l (strcat "1Rb" (rtos x 2 0)))
    (if  (= (get_tile l) "1" )
        (setq ah:col1 x)
    )
    (setq x (+ x 1))
)
(princ)
)

(defun col2 ( / j )
    (setq x 1)
    (repeat (length ah:butlst2)
        (setq j (strcat "2Rb" (rtos x 2 0)))
        (if  (= (get_tile j) "1" )
            (setq ah:col2 x)
         )
        (setq x (+ x 1))
    )
	(princ)
)


(defun AHlist2col (ahdef1 ahdef2  toplabel ah:butlst ah:butlst2 layoutlst / fo fname x  k )

(setq len1 (length ah:butlst) len2 (length ah:butlst2))

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))

(write-line  "AHlist2col : dialog 	{" fo)
(write-line  (strcat " label = " (chr 34) toplabel (chr 34) ";" ) fo)
(write-line "	: row	{" fo)
  (write-line "	: boxed_column 	{" fo)
  (write-line ": list_box { label = \" Select layout \" ; key = \"lst\" ;" fo)
  (write-line  "allow_accept = true; height = 20 ;" fo)
  (write-line "multiple_select = \" False \" ;" fo)
  (write-line " } " fo)
    (write-line "width = 40 ;" fo)
  (write-line " } " fo)
(write-line "	: boxed_radio_column 	{" fo)
(write-line  (strcat " width = 24  ;")  fo)
(setq x 1)
(write-line  (strcat " label = " (chr 34) (nth 0 ah:butlst) (chr 34) " ;" )fo)
(repeat (- (length ah:butlst) 1)
    (write-line "	: radio_button	{" fo)
    (write-line  (strcat "key = "  (chr 34) "1Rb" (rtos  x  2 0)  (chr 34) ";") fo)
    (write-line  (strcat "label = " (chr 34) (nth x  ah:butlst) (chr 34) ";") fo)
    (write-line "	}" fo)
    (write-line "spacer_1 ;" fo)
    (setq x (+ x 1))
)
(if (< len1 len2)
    (repeat (- len2 len1)
    (write-line "spacer_1 ;" fo)
    )
)
(write-line "	}" fo)
(write-line "	: boxed_radio_column 	{" fo)
(write-line  (strcat " width = 24 ;")  fo)
(setq x 1)
(write-line  (strcat "	label = " (chr 34) (nth 0 ah:butlst2) (chr 34) " ;" )fo)
(repeat (- (length ah:butlst2) 1)
    (write-line "	: radio_button	{" fo)
    (write-line  (strcat "key = "  (chr 34) "2Rb" (rtos x  2 0)  (chr 34) ";") fo)
    (write-line  (strcat "label = " (chr 34) (nth x  ah:butlst2) (chr 34) ";") fo)
    (write-line "	}" fo)
    (write-line "spacer_1 ;" fo)
    (setq x (+ x 1))
)
(if (< len2 len1)
    (repeat  (- len1 len2)
        (write-line "spacer_1 ;" fo)
    )
)
(write-line "	}" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	ok_cancel ;" fo)
(write-line "	}" fo)
(close fo)

(setq dcl_id (load_dialog fname))
(if (not (new_dialog "AHlist2col" dcl_id) )
    (exit)
)
(start_list "lst")
  (mapcar (function add_list) layoutlst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq laynum $value)")
(setq x 1)
(repeat (- (length ah:butlst) 1)
    (setq k (strcat "1Rb" (rtos x 2 0)))
  (action_tile k  (strcat "(setq ah:2col "  (rtos x 2 0) ")" ))
    (if (= ahdef1 x)(set_tile k "1"))
    (setq x (+ x 1))
)
(setq x 1)
(repeat (- (length ah:butlst2)1)
    (setq k (strcat "2Rb" (rtos x 2 0)))
   (action_tile k  (strcat "(setq ah:2col2 "  (rtos x 2 0) ")" ))
    (if (= ahdef2 x)(set_tile k "1"))
    (setq x (+ x 1))
)

(action_tile "lst" "(setq layname $value)")
(action_tile "accept"  "(if (= ah:2col nil) (setq  ah:2col 1)(col1)) (if (= ah:2col2 nil) (setq  ah:2col2 1)(col2))(done_dialog)")
(action_tile "cancel" "(done_dialog) (exit)")
(start_dialog)
(unload_dialog dcl_id)
(vl-file-delete fname)

(princ)
) ; end defun

 

0 Likes
Message 23 of 30

thomas_schluesselberger
Advocate
Advocate

Hi!

 

- When testing in the example-drawing, the windows pops up like it should.

But when changing values and pressing "ok", the block gets deleted an nothing happens.

Here is what i get in the console:

Command: DBLVIS
-insert Unknown command "-INSERT". Press F1 key for help.

Command: _emc_Planlayout_Prüflegende Unknown command "EMC_PLANLAYOUT_PRÜFLEGENDE". Press F1 key for help.

Command:
Command: 1

Command: 1

command: 0

command: miss; Error: Bad argument type: lselsetp nil

 

- When testing in another drawing, the window doesn't pops up.

Here is what i get in the console:

Command: DBLVIS
-insert Unknown command "-INSERT". Press F1 key for help.

Command: _emc_Planlayout_Prüflegende Unknown command "EMC_PLANLAYOUT_PRÜFLEGENDE". Press F1 key for help.

Command:
Command: 1

Command: 1

command: 0

Command: ; Error: ActiveX server returned error: unknown name: "GETDYNAMICBLOCKPROPERTIES"

 

0 Likes
Message 24 of 30

Sea-Haven
Mentor
Mentor

Just copy this line only to command line if it errors then the block may not exist I did not check for that.

 

(command "-insert" "_emc_Planlayout_Prüflegende" '(0 0 0) 1 1 0)

 Please let me know.

0 Likes
Message 25 of 30

thomas_schluesselberger
Advocate
Advocate

Hi,

 

thats what i'm getting when entering youre command:

Command: (command "-insert" "_emc_Planlayout_Prüflegende" '(0 0 0) 1 1 0)
-insert Unknown command "-INSERT". Press F1 key for help.

Command: _emc_Planlayout_Prüflegende Unknown command "EMC_PLANLAYOUT_PRÜFLEGENDE". Press F1 key for help.

Command:
Command: 1

Command: 1

command: 0

Command: nil

 

But the block does exist.

 

0 Likes
Message 26 of 30

Sea-Haven
Mentor
Mentor

The "_emc_Planlayout_Prüflegende" was the name of the block you said needed to be used, the error is that the block does not exist in the dwg. Just do a normal insert and select that block from list, I expect it is not there. If it is post the dwg your testing.

SeaHaven_0-1687307196089.png

The "-insert" method I have been using for like 40 years. In all brands of CAD. What CAD are you using.

 

PS check your attributes in the block insert at 0,0,0 but attribute at X= 205852.3366 Y= 129941.2987 ??

 

0 Likes
Message 27 of 30

thomas_schluesselberger
Advocate
Advocate

@Sea-Haven  schrieb:

The "_emc_Planlayout_Prüflegende" was the name of the block you said needed to be used (but the first _ is missing, at console there stands: 'Unknown command "EMC_PLANLAYOUT_TESTING LEGEND"'), the error is that the block does not exist in the dwg (it does exist i see it). Just do a normal insert and select that block from list, I expect it is not there. If it is post the dwg your testing (i cant send you the other dwg but i also tested it with the dwg i sent you at first and when using the LISP it opens the window correctly. But when changing settings of a block it deletes it?, at console there stands: 'command: miss; Error: Bad argument type: lselsetp nil').

SeaHaven_0-1687307196089.png

The "-insert" method I have been using for like 40 years. In all brands of CAD. What CAD are you using.

(i'm using AutoCAD 2023 - German Version, maybe the "-insert" command doesnt exist in german version?)

 

PS check your attributes in the block insert at 0,0,0 but attribute at X= 205852.3366 Y= 129941.2987 ??

(thats intentionally)


 

0 Likes
Message 28 of 30

Sea-Haven
Mentor
Mentor

Ok it may be the German version.

 

But this should work please try. The correct syntax pretty sure  "_-insert" maybe try it before using 2nd option, filedia. Even use what you type for "Insert" in the German version. Einfügung ?

 

 

(setvar 'filedia 0)
(command "insert" "_emc_Planlayout_Prüflegende" '(0 0 0) 1 1 0)
(setvar 'filedia 1)

 

 

 

 

SeaHaven_0-1687407124043.png

 

 

0 Likes
Message 29 of 30

thomas_schluesselberger
Advocate
Advocate

Hi, i changed "-insert" to "_-insert". I attached a video where you can see what happens.

I don't understand why it inserts a new block? The blocks i want to change already exist.

 

(The foto you sent is wright. Any englisch command works with _ before it. Then the command gets translated automatically.)

0 Likes
Message 30 of 30

Sea-Haven
Mentor
Mentor

The reason I insert the block is when you insert a dynamic block its name becomes "*U23" etc it hides its effective name, but it is still there. So I did a quick and dirty to read the properties, the code is written around a more global approach so say block name can be changed and it will still work for some one else. Rather than search all "*Uxx " blocks and find your block by name. 

 

Yes as its a 1 off solution single block, could just hard code the visibility states, I will leave that for you to do. Alearn lisp task, the info is held in lst1 and lst3

 

(AHlist2col 1 1 "Select visibilty" lst1 lst3 lays)

 

0 Likes