Accessing Prims

Get a Reference to a prim

Getting references to prims lets you read and write to their attributes and lets you pass them to APIs.

Get a Reference by using the prim’s stage path

usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
my_prim_path = "World/building/window/"
my_prim = stage.GetPrimAtPath(my_prim_path)

Getting cached prims

For performance reasons some API’s use cached versions of prims and the stage. prim_id is an ID to the cached prim with the path in the string var my_prim_path and stage_id is an ID for the cached stage.

from pxr import PhysicsSchemaTools, UsdUtils

prim_id = PhysicsSchemaTools.sdfPathToInt(my_prim_path)
stage_cache = UsdUtils.StageCache.Get()
usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
stage_id = stage_cache.GetId(stage).ToLongInt()