Extension: omni.kit.viewport.utility-2.0.1 |
Documentation Generated: Nov 13, 2025 |
Usage Examples#
Retrieve Active Viewport and Camera#
from omni.kit.viewport.utility import (
get_active_viewport,
get_viewport_from_window_name,
get_active_viewport_and_window,
get_active_viewport_window
)
# Retrieve the active viewport
viewport = get_active_viewport()
# Get viewport from specific window
viewport = get_viewport_from_window_name("Viewport")
# Get both viewport and window
viewport, window = get_active_viewport_and_window()
# Get just the active viewport window
window = get_active_viewport_window()
Camera Information#
from omni.kit.viewport.utility import (
get_active_viewport_camera_path,
get_active_viewport_camera_string,
get_viewport_window_camera_path,
get_viewport_window_camera_string
)
# Get camera path for active viewport
camera_path = get_active_viewport_camera_path()
# Get camera path as string
camera_string = get_active_viewport_camera_string()
# Get camera path for specific window
window_camera_path = get_viewport_window_camera_path("Viewport")
# Get camera path as string for specific window
window_camera_string = get_viewport_window_camera_string("Viewport")
Get Number of Viewports#
from omni.kit.viewport.utility import get_num_viewports
# Get the number of viewports
num_viewports = get_num_viewports()
# Get number of viewports in specific USD context
context_viewports = get_num_viewports("my_context")
Viewport Capture#
import asyncio
from omni.kit.viewport.utility import (
capture_viewport_to_file,
capture_viewport_to_buffer,
get_active_viewport,
next_viewport_frame_async
)
# Capture to file
viewport = get_active_viewport()
output_file_path = "/tmp/path/to/output/image.png"
capture_helper = capture_viewport_to_file(viewport, file_path=output_file_path)
# Wait for the capture to complete
async def wait_for_capture():
await capture_helper.wait_for_result(completion_frames=30)
asyncio.ensure_future(wait_for_capture())
# wait for a few frames
async def wait_for_frames():
viewport = get_active_viewport()
# Wait for next viewport frame
await next_viewport_frame_async(viewport)
# Wait for multiple frames
await next_viewport_frame_async(viewport, n_frames=5)
asyncio.ensure_future(wait_for_frames())
# Capture with HDR enabled
capture_helper = capture_viewport_to_file(
viewport,
"/tmp/path/to/output_hdr.exr",
is_hdr=True
)
# Capture to buffer with callback
def on_capture(*args, **kwargs):
print(f"Captured image data")
capture_viewport_to_buffer(viewport, on_capture)
# Capture to buffer with HDR
capture_viewport_to_buffer(viewport, on_capture, is_hdr=True)
Viewport Framing#
from omni.kit.viewport.utility import (
frame_viewport_prims,
frame_viewport_selection,
get_active_viewport
)
# Frame specified primitives in the active viewport
primitives_to_frame = ["/World/MyPrim1", "/World/MyPrim2"]
viewport = get_active_viewport()
frame_viewport_prims(viewport, prims=primitives_to_frame)
# Frame the current selection in viewport
frame_viewport_selection(viewport)
# Frame selection without specifying viewport (uses active viewport)
frame_viewport_selection()
Viewport Messaging#
from omni.kit.viewport.utility import post_viewport_message, get_active_viewport
# Post a message to the active viewport
viewport = get_active_viewport()
post_viewport_message(viewport, "This is a test message")
# Post a message with a custom message ID
post_viewport_message(viewport, "Custom message", message_id="my_message_id")
Viewport Interaction Control#
from omni.kit.viewport.utility import (
disable_selection,
disable_context_menu,
get_active_viewport,
get_active_viewport_window
)
# Disable selection in the active viewport
viewport = get_active_viewport()
disable_handle = disable_selection(viewport)
# Selection is now disabled; to re-enable, delete the handle
del disable_handle
# Disable selection with click disabled too
disable_handle = disable_selection(viewport, disable_click=True)
del disable_handle
# Disable context menu for specific viewport
viewport_window = get_active_viewport_window()
context_menu_handle = disable_context_menu(viewport_window)
del context_menu_handle
# Disable context menu globally for all viewports
global_context_menu_handle = disable_context_menu()
del global_context_menu_handle
Create New Viewport Window#
from omni.kit.viewport.utility import create_viewport_window
from pxr import Sdf
# Create a new viewport window with default settings
new_window = create_viewport_window(name="My Custom Viewport")
# Create viewport window with custom dimensions and position
custom_window = create_viewport_window(
name="Custom Viewport",
usd_context_name="",
width=800,
height=600,
position_x=100,
position_y=100,
camera_path=Sdf.Path("/OmniverseKit_Top")
)
AOV Management#
from omni.kit.viewport.utility import (
add_aov_to_viewport,
get_active_viewport
)
viewport = get_active_viewport()
# Add single AOV to viewport
success = add_aov_to_viewport(viewport, "diffuse")
# Add multiple AOVs to viewport
success = add_aov_to_viewport(viewport, ["diffuse", "specular", "normals"])
Drag and Drop Support#
from omni.kit.viewport.utility import create_drop_helper
def on_drop_accepted(url):
"""Called when a drop is accepted"""
return True
def on_drop(url, prim_path, viewport_name, usd_context_name):
"""Called when item is dropped"""
print(f"Dropped {url} at {prim_path}")
def on_pick(payload, prim_path, usd_context_name):
"""Called when item is picked/selected"""
print(f"Picked {prim_path}")
# Create drop helper
drop_helper = create_drop_helper(
add_outline=True,
on_drop_accepted_fn=on_drop_accepted,
on_drop_fn=on_drop,
on_pick_fn=on_pick
)
Ground Plane Information#
from omni.kit.viewport.utility import get_ground_plane_info, get_active_viewport
viewport = get_active_viewport()
# Get ground plane info with orthographic special handling
normal, planes = get_ground_plane_info(viewport, ortho_special=True)
print(f"Ground plane normal: {normal}")
print(f"Ground plane axes: {planes}")
# Get ground plane info without orthographic special handling
normal, planes = get_ground_plane_info(viewport, ortho_special=False)