-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_usd_metadata.py
More file actions
63 lines (46 loc) · 1.54 KB
/
clean_usd_metadata.py
File metadata and controls
63 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""
Clean USD Metadata Script
This script removes the usd_ultimate:session_data from a USD file's customLayerData
to fix any corruption issues.
Usage:
python clean_usd_metadata.py /path/to/file.usd
"""
import sys
from pxr import Usd, Sdf
def clean_usd_metadata(usd_path: str):
"""
Remove usd_ultimate session metadata from a USD file.
Args:
usd_path: Path to USD file to clean
"""
print(f"Opening USD file: {usd_path}")
# Open the layer directly (not as a stage)
layer = Sdf.Layer.FindOrOpen(usd_path)
if not layer:
print(f"ERROR: Could not open USD file: {usd_path}")
return False
print(f"Checking customLayerData...")
# Check if session metadata exists
if 'usd_ultimate:session_data' in layer.customLayerData:
print(f"Found session metadata, removing...")
# Get current customLayerData as dict
custom_data = dict(layer.customLayerData)
# Remove the session data key
del custom_data['usd_ultimate:session_data']
# Set it back
layer.customLayerData = custom_data
# Save the layer
layer.Save()
print(f"✓ Session metadata removed and file saved")
return True
else:
print(f"No session metadata found")
return True
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python clean_usd_metadata.py /path/to/file.usd")
sys.exit(1)
usd_path = sys.argv[1]
success = clean_usd_metadata(usd_path)
sys.exit(0 if success else 1)