Viewport in the form

Hi @dale,

I attempted to utilize that idea here but it gives None as a Parent:

    def OnFormClosed(self, sender, e):
        # Close Rogue Viewports
        try:
            if self.viewport_control is not None:
                vpc_viewport = self.viewport_control.Viewport
                # Get the parent view of the viewport
                vpc_parent = vpc_viewport.ParentView

                # Print the parent view
                if vpc_parent:
                    vpc_parent.Close()
                    Rhino.RhinoApp.WriteLine("Parent View: " + vpc_parent.MainViewport.Name)
                else:
                    Rhino.RhinoApp.WriteLine("No parent view found.")

        except Exception as ex:
            Rhino.RhinoApp.WriteLine(f"Close Viewports: {ex}")

When executing a script that creates a viewport control and running this statement to print the active viewports in the model you can see that Custom view shows up:

if __name__ == '__main__':
    CreateMainForm()
    # Get all open views in the document
    views = Rhino.RhinoDoc.ActiveDoc.Views

    # Iterate through each view and print the viewport names
    for view in views:
        viewport = view.ActiveViewport
        Rhino.RhinoApp.WriteLine("Viewport Name: " + viewport.Name)

Print Statement:
Viewport Name: Perspective
Viewport Name: Top
Viewport Name: Front
Viewport Name: Right
Viewport Name: Custom view

This code does seem to properly close the “extra duplicate” viewport on form close (though this would also close a “valid” Custom view if applicable outside of the Eto.Form as well (if someone added a custom floating view from Rhino for instance):

# Form Class Initialization Code Above This ^

    def OnFormClosed(self, sender, e):
        # Close Rogue Viewports
        try:
            if extra_views:
                for view in extra_views:
                    view.Close()

        except Exception as ex:
            Rhino.RhinoApp.WriteLine(f"Close Extra Viewports: {ex}")

def CheckViewports():
    extra_views = []
    # Get all open views in the document
    views = Rhino.RhinoDoc.ActiveDoc.Views

    # Iterate through each view and print the viewport names
    for view in views:
        viewport = view.ActiveViewport
        if viewport.Name == "Custom view":
            extra_views.append(view)

        Rhino.RhinoApp.WriteLine("Viewport Name: " + viewport.Name)
    return extra_views

if __name__ == '__main__':
    extra_views = CheckViewports()