Get the Active Viewport Window

To interact with the active viewport, you can get the active viewport window. ViewportWindow.viewport_api is a ViewportAPI object that allows even further interaction with the viewport.

from omni.kit.viewport.utility import get_active_viewport_window

# Get the default Viewport window
viewport_window = get_active_viewport_window()

print(f"Active ViewportWindow is {viewport_window}")
print(f"Viewport is available with .viewport_api, its resolution is: {viewport_window.viewport_api.resolution}")

# get_active_viewport_window can fail if querying for a specific ViewportWindow that doesn't exists
non_existent_viewport_window_name = "This Viewport Doesn't Exist"
non_existent_viewport_window = get_active_viewport_window(window_name=non_existent_viewport_window_name)

print(f"Viewport window named {non_existent_viewport_window_name} is {non_existent_viewport_window}")