Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- node = hou.pwd()
- stage = node.editableStage()
- # Add code to modify the stage.
- # Use drop down menu to select examples.
- from pxr import Usd, UsdShade
- def find_unique_asset_paths(stage, prim_path):
- # Open the stage and get the root prim
- root_prim = stage.GetPrimAtPath(prim_path)
- if not root_prim:
- raise ValueError(f"Prim path '{prim_path}' does not exist in the stage.")
- # Set to store unique asset paths
- unique_asset_paths = set()
- # Recursive function to traverse prims
- def traverse_prim(prim):
- for child in prim.GetAllChildren():
- # Check if prim is a UsdShadeShader
- if child.IsA(UsdShade.Shader):
- shader = UsdShade.Shader(child)
- # Check if the shader has an attribute called inputs:file
- file_attr = shader.GetInput("file")
- if file_attr:
- # Add the value to the set of unique paths
- asset_path = file_attr.Get()
- #if isinstance(asset_path, str):
- unique_asset_paths.add(asset_path.path)
- # Traverse further into children
- traverse_prim(child)
- # Start traversal from the root prim
- traverse_prim(root_prim)
- # Log the unique asset paths
- print("Unique USD Asset Paths:")
- for path in unique_asset_paths:
- print(path)
- return list(unique_asset_paths)
- # Usage example
- prim_path = "/master/shading"
- unique_paths = find_unique_asset_paths(stage, prim_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement