Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pxr import Usd
- import os
- def get_basename_of_file_path_attr(prim, attr_name):
- """
- Returns the basename of the file path attribute as a string.
- Parameters:
- prim (Usd.Prim): The USD prim containing the attribute.
- attr_name (str): The name of the attribute (e.g., "inputs:texture:file").
- Returns:
- str: The basename of the file path if the attribute exists and is valid; otherwise, None.
- """
- # Get the attribute
- attr = prim.GetAttribute(attr_name)
- # Check if attribute exists and has a value
- if attr and attr.HasAuthoredValue():
- # Get the file path as a string
- file_path = attr.Get()
- # Extract and return the basename
- return os.path.basename(file_path)
- else:
- print(f"Attribute '{attr_name}' does not exist or has no value.")
- return None
- # Usage example
- # Assuming you have a USD stage and a prim
- stage = Usd.Stage.Open("path_to_your_stage.usda")
- prim = stage.GetPrimAtPath("/LightPrimPath")
- basename = get_basename_of_file_path_attr(prim, "inputs:texture:file")
- print("Basename:", basename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement