make paths relative

This commit is contained in:
Nathan
2025-12-19 17:12:58 -07:00
parent 4c8d6b20b3
commit 6f46b3fce3
2 changed files with 114 additions and 4 deletions

View File

@@ -166,10 +166,46 @@ def remap_texture_paths(blend_file_path, move_log_path):
if node_remapped_count > 0:
remapped_count += node_remapped_count
# Convert any remaining absolute paths in image datablocks to relative
# (ignoring images from linked files)
print("\nConverting absolute image paths to relative...")
abs_to_rel_count = 0
for image in bpy.data.images:
# Skip images from linked files (library datablocks)
if image.library:
continue
if not image.filepath:
continue
# Check if path is absolute
if os.path.isabs(image.filepath):
try:
# Convert to relative path
rel_path = bpy.path.relpath(image.filepath, blend_file_dir)
if rel_path != image.filepath:
image.filepath = rel_path
print(f" Converted to relative: {os.path.basename(image.filepath)}")
abs_to_rel_count += 1
except Exception as e:
# If conversion fails, skip it (might be a network path or other issue)
pass
if abs_to_rel_count > 0:
remapped_count += abs_to_rel_count
print(f"\n=== REMAPPING SUMMARY ===")
print(f"Paths remapped: {remapped_count}")
print(f"Broken references (not found): {not_found_count}")
# Make all paths relative after remapping (this handles other datablock types)
try:
print(f"\nMaking paths relative...")
bpy.ops.file.make_paths_relative()
print(f" Converted absolute paths to relative paths")
except Exception as e:
print(f" Warning: Failed to make paths relative: {e}")
# Save the blend file
try:
print(f"\nSaving blend file...")