Advertisement
thureinfree

merge_prims_by_mtl

Jun 7th, 2024 (edited)
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import os
  2. import glob
  3. import hou
  4.  
  5. # User inputs
  6. folder_path = '/server/hdri'
  7. file_mask = '*_acescg.exr'
  8. exclusion_wildcards = 'blank,do_not_use'  # Comma-separated exclusion wildcards
  9. start_frame = 1001
  10. interval = 5  # Interval frame number to make changes over time
  11.  
  12. # Get the Python SOP node
  13. node = hou.pwd()
  14. geometry = node.geometry()
  15.  
  16. # Get all the .exr files from the folder with the given mask
  17. file_pattern = os.path.join(folder_path, file_mask)
  18. exr_files = sorted(glob.glob(file_pattern))
  19.  
  20. if not exr_files:
  21.     raise ValueError(f"No files found with pattern: {file_pattern}")
  22.  
  23. # Filter out files based on exclusion wildcards
  24. exclusion_list = [wildcard.strip() for wildcard in exclusion_wildcards.split(',')]
  25. filtered_files = [f for f in exr_files if not any(excl in f for excl in exclusion_list)]
  26.  
  27. if not filtered_files:
  28.     raise ValueError("No files left after applying exclusion wildcards.")
  29.  
  30. # Set file_name attribute as a detail attribute based on the current frame
  31. geometry.addAttrib(hou.attribType.Global, 'file_name', '')
  32. current_frame = hou.intFrame()
  33.  
  34. # Determine the index of the file to use based on the current frame
  35. if current_frame >= start_frame:
  36.     index = (current_frame - start_frame) // interval
  37.     if index < len(filtered_files):
  38.         base_name = os.path.basename(filtered_files[index])
  39.         geometry.setGlobalAttribValue('file_name', base_name)
  40.     else:
  41.         geometry.setGlobalAttribValue('file_name', '')  # Set to empty if out of range
  42. else:
  43.     geometry.setGlobalAttribValue('file_name', '')  # Set to empty if before start_frame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement