Hwo to find all overrides below a prim

Hello,

I´ve created an override of a sub node in a referenced USD…

def "Root"
{
    def Xform "Graph"
    {
        def Xform "Test"
        {
            def Xform "Geometry" (
                instanceable = false
                prepend references = @omniverse://localhost/Users/XcalibuR/Assets/Catalog/Back_pillow_cushion1_55.glb.usd@
            )
            {
                over "back_pillow_cushion1_55"
                {
                    rel material:binding = </Root/Looks/TestMaterial>
                }
            }
        }
    }
}

So far so good… in the next update cycle I want to replace the exising overrides with potential new, so I have to find the current overrides under “Geometry” in the first step (to remove those not active anymore). But when calling GetChildren oder Travers (on stage) I always get the prims inside the referenced usd… but I only want the overrides (back_pillow_cushion1_55).

I tried already this (and several other things)…

UsdPrimRange children = stage->Traverse().AllPrims(geometryPrim);

for (UsdPrim childPrim : children)
{
	if (childPrim.GetSpecifier() == SdfSpecifier::SdfSpecifierOver)
	{
		std::string xxx = childPrim.GetPrimPath().GetString();
	}
}

Can anyone give me a hint how to find those overrides?

Thanks

Carl

This can get tricky because you need to query the data pre-composition a layer at a time. For your case, you may be talking about overrides in a single layer so it may not be too hard. I recently wrote this code figure out spec authored within variants. I think the concepts in this snippet will apply to what you want to do:

import omni.usd
from pxr import Usd, Sdf
import json
​
​
def get_specs_in_variants(layer:Sdf.Layer, prim_path, skip_prim_overs=True):
    """ Gets the paths for authored specs in variants
        Args:
            layer: The SdfLayer to traverse
            prim_path: The prim_path where the VariantSets are authored.
            skip_prim_overs: Skip prims with over specifier.
    """
    prim_spec = layer.GetPrimAtPath(prim_path)
    specs = {}
    for vset_spec in prim_spec.variantSets:
        specs[vset_spec.name] = {}
        for variant_spec in vset_spec.variants:
            print(variant_spec.primSpec)
            specs[vset_spec.name][variant_spec.name] = {"properties":[], "prims":[]}
​
            def visit(path):
                if path.IsPrimPath():
                    if skip_prim_overs:
                        prim:Sdf.PrimSpec = layer.GetPrimAtPath(path)
                        if prim.specifier != Sdf.SpecifierOver:
                            specs[vset_spec.name][variant_spec.name]["prims"].append(path)
                    else:
                        specs[vset_spec.name][variant_spec.name]["prims"].append(path)
​
                elif path.IsPropertyPath():
                    specs[vset_spec.name][variant_spec.name]["properties"].append(path)
​
            layer.Traverse(variant_spec.primSpec.path, visit)
    
    return specs
​
​
stage = omni.usd.get_context().get_stage()
layer:Sdf.Layer = Sdf.Layer.FindOrOpen(stage.GetRootLayer().identifier)
specs = get_specs_in_variants(layer, layer.defaultPrim)
print(json.dumps(specs, sort_keys=True, indent=4, default=lambda obj: str(obj) if isinstance(obj, Sdf.Path) else obj))

Here’s a sample stage if you’re curious to test my function:
VariantSetWithLocalDefaults.usda (5.3 KB)

Hi Mati,

thank you very much… the hint to PrimSpecs helped a lot 👍

Carl

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.