Create new floating viewport with a specific viewport resolution

Hi All,
Is there a way to create a new floating viewport with specific 960x540 resolution?
Trying to do it in python. thanks a lot!

If possible could that option be built into -newfloatingviewport command?

This just worked for me, after 2 attempts with ChatGPT. Take it for what it’s worth.

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

def create_floating_viewport():
    # Use the Rhino command to create a new floating viewport
    rs.Command("-NewFloatingViewport", True)
    
    # Get the active view, which is the new floating viewport
    view = sc.doc.Views.ActiveView
    if not view:
        print("Failed to create a floating viewport.")
        return
    
    # Set the size of the floating viewport
    view.Width = 960
    view.Height = 540
    
    # Optionally set a name for the viewport
    view.MainViewport.Name = "Custom Viewport"
    
    # Redraw the views to apply changes
    view.Redraw()
    
    print(f"Floating viewport '{view.MainViewport.Name}' created with size 960x540.")

# Run the function
create_floating_viewport()

Hi @Iyang_Huang,

This command macro works:

_-NewFloatingViewport _Enter
_-ViewportProperties _Size 960 540 _Enter

or Python:

#! python3
import Rhino

Rhino.RhinoApp.RunScript("_-NewFloatingViewport _Enter", False)
Rhino.RhinoApp.RunScript("_-ViewportProperties _Size 960 540 _Enter", False)

– Dale

1 Like

thank you so much!

thanks for the quick reply!