Advertisement
thureinfree

remove st attributes

Oct 31st, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. from pxr import Usd, UsdGeom
  2.  
  3. def remove_st_primvars(prim):
  4. """
  5. Recursively removes 'st' primvars using PrimvarsAPI from the given prim and all its children.
  6. """
  7. primvars_api = UsdGeom.PrimvarsAPI(prim)
  8. if primvars_api.HasPrimvar("st"):
  9. primvar = primvars_api.GetPrimvar("st")
  10. primvar.GetAttr().Clear()
  11. print(f"'st' primvar removed from {prim.GetPath()}")
  12.  
  13. # Recursively remove 'st' from all child prims
  14. for child in prim.GetChildren():
  15. remove_st_primvars(child)
  16.  
  17. # Access the stage in Houdini's LOPs context
  18. stage = hou.node('/path/to/your/python_lop').stage()
  19.  
  20. # Specify the top-level prim path
  21. top_prim_path = "/path/to/your/top/prim"
  22. top_prim = stage.GetPrimAtPath(top_prim_path)
  23.  
  24. # Apply the function to the top prim and its descendants
  25. if top_prim:
  26. remove_st_primvars(top_prim)
  27. else:
  28. print(f"No prim found at path {top_prim_path}")
  29.  
  30. # Save the stage to persist changes
  31. stage.GetRootLayer().Save()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement