Author Topic: Turn all layout viewports ON-OFF in a drawing  (Read 455 times)

0 Members and 1 Guest are viewing this topic.

Ndruu

  • Mosquito
  • Posts: 5
Turn all layout viewports ON-OFF in a drawing
« on: February 07, 2024, 11:02:34 AM »
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.  :idiot2: 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?

Code: [Select]
(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)
)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Turn all layout viewports ON-OFF in a drawing
« Reply #1 on: February 07, 2024, 03:26:30 PM »
Try using this to get the VPORTS:
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rod

  • Newt
  • Posts: 185
Re: Turn all layout viewports ON-OFF in a drawing
« Reply #2 on: February 07, 2024, 04:01:27 PM »
FYI Turning off the layer the viewports are on will still be slow when switching between layouts. But freezing the layer will make a big difference.
"All models are wrong, some models are useful" - George Box

Ndruu

  • Mosquito
  • Posts: 5
Re: Turn all layout viewports ON-OFF in a drawing
« Reply #3 on: February 07, 2024, 06:29:45 PM »
Try using this to get the VPORTS:
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))

Thank you ronjonp! Unfortunately it didn't work, it still gives me the same "Automation Error. Not in paperspace" message.
The last break point in the code is at this line:
Code: [Select]
(vla-put-viewporton (vlax-ename->vla-object (ssname ss i)) :vlax-false)


FYI Turning off the layer the viewports are on will still be slow when switching between layouts. But freezing the layer will make a big difference.

Rod: Thank you too! I tried it and I could not measure any difference. Switching from one layout to another took 33s and another 25s to regenerate. I tried it on a drawing that has 380k objects, 48 xrefs in it.

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Turn all layout viewports ON-OFF in a drawing
« Reply #4 on: February 08, 2024, 11:09:46 AM »
According to Autodesk help, you should use the (vla-Display) method to control the display of a viewport on or off:
Code - Auto/Visual Lisp: [Select]
  1. (vla-Display (vlax-ename->vla-object (ssname ss i)) :vlax-true)
  2.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt