Change the Viewport’s Active Camera#
The ViewportWindow
and ViewportAPI
classes offer a number of ways to interact with the viewport. This snippet shows how you can change the active camera for a viewport.
from omni.kit.viewport.utility import get_active_viewport
camera_path = "/World/Camera/MyNewCamera"
viewport = get_active_viewport()
if not viewport:
raise RuntimeError("No active Viewport")
# Set the Viewport's active camera to the
# camera prim path you want to switch to.
viewport.camera_path = camera_path