I know this is an old thread but hopefully it might get some new hits. Has anybody figured out a way to update (restore) layer states once and have that update propagate throughout the entire drawing?? In other words, making an update (restore) to one viewport but then have that update restore to all other viewports that have that same layer state? (instead of having to go to each individual viewport and manually doing a restore via the LS Manager) I did find a lisp on another forum that does a restore throughout the drawing, "but" it applies the updated layer state to ALL viewports regardless of their current state. Well I don't want to apply the same LS to all viewports, just the ones that match the updated one. I would imagine this lisp can be modified to include a way to match the layer state? Just in case it's possible, here is the current lisp. It does work, but like I said it will apply one layer state to all viewports regardless.
Code:
(vl-load-com)
(defun c:LayerStateRestoreAll (/ *error* ss layouts options lastRestored option acDoc n i found)
(defun *error* (msg)
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if
(and
(setq ss (ssget "_x" '((0 . "VIEWPORT"))))
(< (length (setq layouts (layoutlist))) (sslength ss))
(setq options (layerstate-getnames))
(not (initget
(setq options
(vl-string-right-trim
" "
(apply
'strcat
(mapcar (function (lambda (x) (strcat x " ")))
options
)
)
)
)
)
)
(or
(setq option
(getkword
(strcat
"\nEnter layer state to restore to all viewports ["
(vl-string-translate " " "/" options)
"]"
(if (setq lastRestored (layerstate-getlastrestored))
(strcat "<" lastRestored ">:")
":"
)
)
)
)
(setq option
(cond (lastRestored lastRestored)
((= 1 (length options)) (car options))
)
)
)
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(foreach layout layouts
(setq found (setq ss nil))
(if (setq ss
(ssget "_x" (list '(0 . "VIEWPORT") (cons 410 layout)))
)
(progn
(repeat (setq i (setq n (sslength ss)))
(if found
(layerstate-restore
option
(ssname ss (setq i (1- i)))
4
)
(setq found (setq i (1- i)))
)
)
(prompt
(strcat "\nLayer state \""
option
"\" applied to "
(itoa (setq n (1- n)))
" viewport"
(if (= 1 n)
""
"s"
)
" on \""
layout
"\" tab. "
)
)
)
)
)
)
(cond (ss (prompt "\n** No layer states found ** "))
((prompt "\n** No viewports found ** "))
)
)
(*error* nil)
)