Selecting the same dynamic block in all layouts - PAPERSPACE.

Selecting the same dynamic block in all layouts - PAPERSPACE.

kathyszturo
Explorer Explorer
1,362 Views
16 Replies
Message 1 of 17

Selecting the same dynamic block in all layouts - PAPERSPACE.

kathyszturo
Explorer
Explorer
Hello 
Below is a question someone else posted a while ago… now I am looking for a similar solution in AutoCAD PAPERSPACE. I believe a Lisp is required. Please help.🙏

“Selecting the same dynamic block in all layouts - PAPERSPACE.
can this be done?
I have a dynamic block with only a visibility action and I need to select ALL of the these blocks in ALL the layouts and change the visibility name from "V1" to "V2" also I was thinking can this be done globally with other actions, simple ex.: dynamic north arrow after it's been inserted into the drawing and now you would like to change the rotation of all the north arrows to be the same for all of them. and many other uses.

to sum it up, can you globally select all of one kind of DB and globally change a given action. filter can't work because it returns a "*U###" for said block and gatte doesn't work since their are no attributes.

I even tried setting "V2" to the top of the list and then resetting the block but all it did was reset that one block within that layout only 😞
0 Likes
Accepted solutions (1)
1,363 Views
16 Replies
Replies (16)
Message 2 of 17

JBerns
Advisor
Advisor

@kathyszturo,

I think this should be possible with LISP.

I think you would have to loop through all the paperspace layouts and process the found dynamic blocks in that layout. At least, that would be my approach. Have you tried writing any code so far?

Please include a simplified drawing that contains the dynamic block so the community does not have to start from scratch.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 3 of 17

ВeekeeCZ
Consultant
Consultant

Try this one. 

 

(vl-load-com)

(defun c:SelectDynBlocks ( / n p v s l)
  
  (if (and (setq n (getstring T "\nBlock name: "))
	   (setq p (getstring T "\nBlock property: "))
	   (setq v (getstring T "\nProperty value: "))
	   (setq s (ssget "_X" '((0 . "INSERT") (410 . "~Model"))))
	   (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	   (setq l (vl-remove-if
		     '(lambda (b) (and (not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list b "BlockTableRecord/Name")))))
				       (= x n)
				       (not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list b (strcat "AcDbDynBlockProperty" p))))))
				       (= x v)
				       ))
		     l))
	   (mapcar '(lambda (e) (ssdel e s)) l)
	   )
    (sssetfirst nil s))
  (princ)
  )

 

Message 4 of 17

ВeekeeCZ
Consultant
Consultant

BTW you can easily add one more prompt to specify the space. Whether it is Model, ~Model, * or Layoutname or Layout[3,4]...

0 Likes
Message 5 of 17

JBerns
Advisor
Advisor

@ВeekeeCZ,

As written, this would be an inverted or opposite selection, correct?

When I tested, it selected all dynamic blocks except what I specified for block name, property, and value.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 6 of 17

ВeekeeCZ
Consultant
Consultant

@JBerns 

 

ohh, right. My bad, thanks. I guess all we need is removing -not from vl-remove-if-not fnc. Thx

0 Likes
Message 7 of 17

Sea-Haven
Mentor
Mentor

Just a side comment "change the rotation of all the north arrows" no need for a dynamic block you can read the twist angle of a viewport then rotate the north arrow to match, the arrow is a plain block. Just ask how to.

 

Part 2 for those of us that cant use get/setproperty, just get the blocks in a layout, then check their effective name for a match, then I use Lee-mac dynamic properties lisp to set the visibility. Can do select a single block and retrieve effective name, then display visibilty states and choose the new one to be used for the changes.

SeaHaven_0-1701225514775.png

 

No dwg to play with so no code.

0 Likes
Message 8 of 17

kathyszturo
Explorer
Explorer

Please see sample of Dynamic Block.

What I am trying to do is once I change for example "issued for permitting" on one paperspace layout I would like the block to change throughout all the paperspace layouts simultaneously. 

 

Thank you,

0 Likes
Message 9 of 17

JBerns
Advisor
Advisor

@kathyszturo,

 

Thanks for sharing the sample drawing.

 

I think that kind of "automatic" change to all occurrences of the DB would require reactors.

As I understand a reactor, it is code running in memory to monitor the state of an object.

If the object changes, other code is automatically run to perform some task.

There is certainly people in this community that could likely write that kind of code.

 

Alternatively, you might consider a LISP routine that could change the DB Visibility state without selecting anything.

For example, a LISP command named ChangeDwgStamp.

Once run it would ask which state: Preliminary, Construction, Permitting

Once the user makes a selection, the code finds all occurrences in the layouts and then changes the Visibility1 property according to the user selection.

 

The code by @ВeekeeCZ could be a good starting point.

 

Let us know your thoughts.

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 10 of 17

JBerns
Advisor
Advisor

@kathyszturo,

 

I quick search of the forum found this code by @Lee_Mac which could be modified to suit your need I think.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-visibility-states-in-dynami... 

 

Regards,

Jerry 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 11 of 17

JBerns
Advisor
Advisor

@kathyszturo,

 

Add this code to the code by @Lee_Mac . See link above. Big thanks to Lee for his code example.

;;; Command to change visibility state of all dynamic blocks
;;; named "PRELIM STAMP" in all layouts.
;;; Developed for @kathyszturo
;;; Portions copyright by Lee Mac
;;; 2023-11-29 Jerry Berns

(defun C:ChangeDwgStamp ( / ans blk idx obj sel vis )

  ;; initialize keywords and get drawing state
  (initget "Preliminary Construction Permitting")
  (setq ans (getkword "\nSelect Drawing Stamp [Preliminary/Construction/Permitting] <Preliminary>: "))

  ;; check for null response
  (if (null ans)
    (setq ans "PRELIMINARY")
    (setq ans (strcase ans))
  ) ;_if

  ;; set visibility state
  (cond
    ((= (strcase ans) "PRELIMINARY") (setq vis "PRELIMINARY"))
    ((= (strcase ans) "CONSTRUCTION") (setq vis "ISSUED FOR CONSTRUCTION"))
    ((= (strcase ans) "PERMITTING") (setq vis "ISSUED FOR PERMITTING"))
  ) ;_if

  ;; set block name
  (setq blk "PRELIM STAMP")

  ;; find and change all layout occurrences (code by Lee Mac)
  (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model"))))
    (repeat (setq idx (sslength sel))
      (if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
	(LM:SetVisibilityState obj vis)
      ) ;_if
    ) ;_repeat
  ) ;_if
  (princ)
)

 

I welcome your feedback.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 12 of 17

Sea-Haven
Mentor
Mentor
Accepted solution

No need for reactors, a global approach is pick a block, get visibility states and choose which one you want to use, by picking block can get effective name of the "*U123" block. Make a selection inside each layout using filter (cons 410 (getvar 'ctab)) makes it easier, then yes use the great dynamic block code by Lee-mac to change visibility.

 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selecting-the-same-dynamic-block-in-all-layouts-paperspace/td-p/12405888
; global change dynamic block visibilty
; By AlanH Nov 2023
(defun c:wow ( / obj bname lays visval lst ans lay lays ss)

(setq obj (vlax-ename->vla-object (car  (entsel "\nPick block object "))))
(setq bname (vlax-get obj 'effectivename))

(setq lays (layoutlist))

; big thanks to Lee-mac for the dynamic block edit properties
(if (not LM:setdynpropvalue )(load "Dynamic block get-put Lee-mac"))

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))

(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"))
(setq ans (ah:butts 1 "V"  lst))

(foreach lay lays
  (setvar 'ctab lay)
  (command "pspace")
  (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar 'ctab)))))
  (repeat (setq x (sslength ss))
   (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
   (if (= (vlax-get obj 'EffectiveName) bname)
   (LM:SetVisibilityState obj ans)
  )
  )
)

(princ)
)

 

 

SeaHaven_0-1701307382842.png

Make sure the 2 extra programs are saved in a support & trusted path.

 

Message 13 of 17

JBerns
Advisor
Advisor

@Sea-Haven,

 

Very impressive! Great work, Alan!

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 14 of 17

Sea-Haven
Mentor
Mentor

Thank you, I often look at these requests and do a global answer saves the next request from some one else asking for changes to the code to suit their block.

Message 15 of 17

kathyszturo
Explorer
Explorer

OMG It works like a charm.

Thank you so much for this. 

0 Likes
Message 16 of 17

kathyszturo
Explorer
Explorer

Thank you so much for all the help. I am new around here so it is so nice to see how many solutions and suggestions everyone has. So Helpful.

0 Likes
Message 17 of 17

JBerns
Advisor
Advisor

@kathyszturo,

Glad to be of assistance. 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes