Check if a Prim Exists¶
Certain functions may return a Usd.Prim
object, but the Prim may not exist due to an incorrect path or because of changes on the Stage. You can use Usd.Object.IsValid() to check if the Prim is valid or exists.
USD API¶
from pxr import Sdf, Usd
prim_path = Sdf.Path("/World/Hello")
prim: Usd.Prim = stage.GetPrimAtPath(prim_path)
if prim.IsValid():
print("Prim exists!")
Alternatively, Usd.Object
overrides the boolean operator so you can check with a simple boolean expression.
from pxr import Sdf, Usd
prim_path = Sdf.Path("/World/Hello")
prim: Usd.Prim = stage.GetPrimAtPath(prim_path)
if prim:
print("Prim exists!")