How to select camera on our own extension?


I am asking this for our developer.

See this video please:

If I hide the camera with viewport toolbar command, lioke I do in the video,
then how can I connect my own button in our extension to make one of the 3 cameras active in viewport? In other words, how can I select the camera ?


the following snippet should allow you to change viewport camera as well as select it in stage.

import omni.kit.viewport.utility as vu
import omni.usd
from pxr import Sdf

cam_path = "/World/Camera"
vp_api = vu.get_active_viewport()
ctx = omni.usd.get_context()

# change viewport
vp_api.camera_path = cam_path

# select camera used in viewport
ctx.get_selection().set_selected_prim_paths([cam_path], True)

amazing, let us try this!