Usage Examples#
Working with Prims and Selection#
import asyncio
import omni.usd
import omni.kit.test_suite.helpers as helpers
from pxr import Usd
async def prims_selection_example():
# Get the USD context
usd_context = omni.usd.get_context()
# Create a new stage instead of opening an existing one
await usd_context.new_stage_async()
await helpers.wait_stage_loading()
# Now the stage should be available
stage = usd_context.get_stage()
# Create some example prims to work with
stage.DefinePrim("/World", "Xform")
stage.DefinePrim("/World/Sphere", "Sphere")
stage.DefinePrim("/World/Cube", "Cube")
stage.DefinePrim("/World/Looks", "Scope")
# Select specific prims in the stage
await helpers.select_prims(["/World/Sphere", "/World/Cube"])
# Get all prims from the stage (now stage is properly initialized)
all_prims = helpers.get_prims(stage)
for prim in all_prims:
print(f"Found prim: {prim.GetPath().pathString}")
# Get prims excluding specific paths
filtered_prims = helpers.get_prims(stage, exclude_list=["/World/Looks"])
# Delete children under a specific prim path
await helpers.delete_prim_path_children("/World/Looks")
Arranging Windows#
import omni.kit.test
import omni.usd
from omni.kit import ui_test
from pxr import Sdf, UsdShade
from omni.kit.test_suite.helpers import wait_for_viewport_ready, arrange_windows
# Test custom properties UI for NVIDIA IndeX
class TestIndeXPropertiesUI(omni.kit.test.AsyncTestCase):
async def setUp(self):
await super().setUp()
await arrange_windows(
topleft_window="Stage", # Window to place in top-left
topleft_height=400.0, # Height for the window
topleft_width=500.0, # Width for the window
hide_viewport=False # Keep viewport visible
)
Wait for Stage and UI Operations#
from omni.kit import ui_test
from omni.kit.test_suite.helpers as helpers
from omni.ui.tests.test_base import OmniUiTest
class TestHelpers_StageLoading(OmniUiTest):
# Before running each test
async def setUp(self):
await super().setUp()
await arrange_windows("Stage", 256)
# debug only to demonstrate what is happening
helpers.TestSuiteHelpers.stage_event_debug = True
helpers.TestSuiteHelpers.stage_loading_debug = True
# After running each test
async def tearDown(self):
await super().tearDown()
# debug only to demonstrate what is happening
helpers.TestSuiteHelpers.stage_event_debug = False
helpers.TestSuiteHelpers.stage_loading_debug = False
# Test(s)
async def test_helpers_stageloading(self):
await helpers.open_stage(helpers.get_test_data_path(__name__, "bound_shapes.usda")) # from kit\source\extensions\omni.kit.test_suite.helpers\data\tests\bound_shapes.usda
# wait for material to load & UI to refresh
await helpers.wait_stage_loading()
# select prim (as this prim has a material bound to it, KIT will need to load material & any textures)
await helpers.select_prims(["/World/Cylinder"])
await ui_test.human_delay()
# wait for material to load & UI to refresh
await helpers.wait_stage_loading()