We have relatively big files with a lot of xrefs and a whole lot of Layouts with 3-5 viewports (. Switching between Layouts is painfully slow in these drawings. That's why I came up with the idea to turn the viewports OFF, when we don't need them, so switching can be sped up.
I have this little code to do the job for me, but it only works in some cases. You can even run it from Model space.
But it only works if you create the viewports in the same session as when you run the lisp.
Try it: Draw something in Model space, create multiple Layouts then make a viewport on each one.
Run the code AVPOFF and it will turn all viewports off on all Layouts. Save the drawing, close and reopen it and run the code AVPON. It will only turn on those viewports that were on the last activated Layout.
According to the
Autocad help file:
DXF 68 || Viewport status field: || -1 = On, but is fully off screen, or is one of the viewports that is not active because the $MAXACTVP count is currently being exceeded. // 0 = Off // <positive value > = On and active. The value indicates the order of stacking for the viewports, where 1 is the active viewport, 2 is the next, and so forth
DXF 69 || Viewport ID ||
Couldn't find any further description... The problem is Viewport ID resets to 0 every time you close the drawing.
You have to cycle through all layouts to get the true Viewport ID values.
I would like to do this job without alternating through paperspaces. Can it be done?
(defun c:avpoff (/ ss i d1 d2 d3 d4)
(vl-load-com)
(if
(setq ss (ssget "_X"
(list (cons -4 "<AND")
(cons 0 "VIEWPORT")
(cons -4 "!=")
(cons 69 1)
(cons -4 "!=")
(cons 68 0)
(cons -4 "AND>")
)
)
)
(progn
(setq i 0)
(repeat (sslength ss)
(vla-put-viewporton
(vlax-ename->vla-object (ssname ss i))
:vlax-false
)
(setq i (1+ i))
)
)
)
(setvar 'qaflags 0)
(princ "\nDone! All viewports are inactive!")
(princ)
)
(defun c:avpon (/ ss1 i1 d1 d2 d3 d4)
(vl-load-com)
(if
(setq ss1 (ssget "_X"
(list (cons -4 "<AND")
(cons 0 "VIEWPORT")
(cons -4 "!=")
(cons 69 1)
(cons -4 "<")
(cons 68 1)
(cons -4 "AND>")
)
)
)
(progn
(setq i1 0)
(repeat (sslength ss1)
(vla-put-viewporton
(vlax-ename->vla-object (ssname ss1 i1))
:vlax-true
)
(setq i1 (1+ i1))
)
)
)
(princ "\nDone! All viewports are active!")
(princ)
)