Advertisement
thureinfree

usd attribute function

Nov 6th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. from pxr import Usd
  2. import os
  3.  
  4. def get_basename_of_file_path_attr(prim, attr_name):
  5. """
  6. Returns the basename of the file path attribute as a string.
  7.  
  8. Parameters:
  9. prim (Usd.Prim): The USD prim containing the attribute.
  10. attr_name (str): The name of the attribute (e.g., "inputs:texture:file").
  11.  
  12. Returns:
  13. str: The basename of the file path if the attribute exists and is valid; otherwise, None.
  14. """
  15. # Get the attribute
  16. attr = prim.GetAttribute(attr_name)
  17.  
  18. # Check if attribute exists and has a value
  19. if attr and attr.HasAuthoredValue():
  20. # Get the file path as a string
  21. file_path = attr.Get()
  22.  
  23. # Extract and return the basename
  24. return os.path.basename(file_path)
  25. else:
  26. print(f"Attribute '{attr_name}' does not exist or has no value.")
  27. return None
  28.  
  29. # Usage example
  30. # Assuming you have a USD stage and a prim
  31. stage = Usd.Stage.Open("path_to_your_stage.usda")
  32. prim = stage.GetPrimAtPath("/LightPrimPath")
  33. basename = get_basename_of_file_path_attr(prim, "inputs:texture:file")
  34. print("Basename:", basename)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement