Archived post by mikael00794

Hehe yep. This is the painful part of working with the Sdf API. Sdf only works on individual layers, not the composed stage. Since you referenced in the .usd file to the /ROOT prim, technically the only defined primitive in the active layer is the /ROOT prim. The child primitives lives in the referenced usd file. So the steps to get the child prims is roughly: Get the /ROOT prim. Check the reference list for the primitive. Compute the absolute path to the reference usd file. Open the reference usd layer. Get the primitive from this layer instead. Something like this ish:
“`python from pxr import Sdf, Usd
node = hou.pwd()
layer = node.editableLayer() print(‘Editable Layer’, layer)
# This prim is defined on the active editable layer root_sdf_path = Sdf.Path(‘/ROOT’) root_prim = layer.GetPrimAtPath(root_sdf_path) print(‘Root Prim’, root_prim)
# Get reference list from prim on active layer root_prim_ref = root_prim.referenceList.GetAddedOrExplicitItems()[0] ref_layer_path = layer.ComputeAbsolutePath(root_prim_ref.assetPath) print(‘Reference Layer Path’, ref_layer_path) # Open reference ref_layer = Sdf.Layer.FindOrOpen(ref_layer_path)
# Get prim from reference usd. This will use the Sdf.Path from the reference usd layer ctrl_prim = ref_layer.GetPrimAtPath(‘/RIG_Main/carBody_CTRL’) print(‘ctrl_prim’, ctrl_prim) “` Fun times