Closing viewports

Hello,
I wonder if there is any method for closing viewports? I have some scripts for cleaning and managing documents generated from some other models, like removing unwanted entities and so on. And also I feel cravings for having one and single viewport in some of these documents… Is it possible, with Python or Rhinoscript? I see there are lots of methods for handling views, but none of them seems to close a viewport… And I see there is a bit messing with views and viewports, I think it could be handled a bit more people friendly :wink:

I still use Rhino 6, but I am almost ready to move to Rhino 8.

Cheers, Jaro

Hi @jerry.bakowski,

you might use Rhino.Display.RhinoView.Close() eg. to close all floating views below does it:

import scriptcontext

def CloseFloatingViewports():
    for view in scriptcontext.doc.Views.GetStandardRhinoViews():
        if view.Floating == True: view.Close()

if __name__=="__main__":
    CloseFloatingViewports()

should work in Rhino 6+
_
c.

1 Like

Thank you very much, @clement
This almost works, the only drawback is that your script is closing floating viewports only… Maybe you know how to convert a regular one to the floating one?
Cheers, Jaro

Hi @jerry.bakowski, there should be no difference if the view is floating or not. Below is an example which closes all perspective views:

import scriptcontext

def ClosePerspectiveViewports():
    for view in scriptcontext.doc.Views.GetStandardRhinoViews():
        if view.ActiveViewport.IsPerspectiveProjection:
            view.Close()

if __name__=="__main__":
    ClosePerspectiveViewports()

CloseViewExample

What you want to do with your viewport(s) in order to clean them up ? To get eg. back to the default 4 View layout you could use:

scriptcontext.doc.Views.FourViewLayout(True)

_
c.

1 Like

Fantastic, thank you!