From 6f46b3fce31c706b0f9433d6678c027b13c35d79 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 19 Dec 2025 17:12:58 -0700 Subject: [PATCH] make paths relative --- ...-19_18-52Z-blend-file-path-prefix-logic.md | 82 ++++++++++++++++++- remap_texture_paths.py | 36 ++++++++ 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/.specstory/history/2025-12-19_18-52Z-blend-file-path-prefix-logic.md b/.specstory/history/2025-12-19_18-52Z-blend-file-path-prefix-logic.md index a8b043b..62c138a 100644 --- a/.specstory/history/2025-12-19_18-52Z-blend-file-path-prefix-logic.md +++ b/.specstory/history/2025-12-19_18-52Z-blend-file-path-prefix-logic.md @@ -16893,7 +16893,6 @@ _**User**_ _**Agent (model default, mode Agent)**_ - The script reports "No moves found in move log" despite 136 moves. Checking the JSON structure and the Python script's parsing: @@ -16907,7 +16906,6 @@ The script reports "No moves found in move log" despite 136 moves. Checking the --- - Checking how the move log is saved in PowerShell to verify the JSON structure: @@ -16921,7 +16919,6 @@ Checking how the move log is saved in PowerShell to verify the JSON structure: --- - Adding debug output to the Python script to inspect the loaded JSON: @@ -16954,7 +16951,6 @@ Status: **completed** --- - Added debug output and support for both camelCase and PascalCase property names (PowerShell's `ConvertTo-Json` may use PascalCase). The script will: 1. Show what keys are in the JSON data @@ -16966,3 +16962,81 @@ Run the script again to see what's in the JSON and why the moves aren't being fo --- +_**User**_ + +incredible! now we just need to make sure to run bpy.ops.file.make_paths_relative() after remapping the textures. + +--- + +_**Agent (model default, mode Agent)**_ + + +Adding `bpy.ops.file.make_paths_relative()` after remapping to convert absolute paths to relative: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\remap_texture_paths.py + +
+
+ +--- + + + + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\remap_texture_paths.py" +} +``` +Additional data: + +```json +{ + "codeblockId": "cf7dff8c-38d3-4fab-8987-6fc7cd6438ac" +} +``` +Status: **completed** + + +
+
+ +--- + + +Added `bpy.ops.file.make_paths_relative()` after remapping and before saving. The script will: + +1. Remap all texture paths to their new locations +2. Convert all absolute paths to relative paths (for portability) +3. Save the blend file + +This ensures blend files use relative paths, making them portable across different machines and folder structures. + +--- + +_**User**_ + +blendfile Kirk had absolute paths by accident. @pwsh (1-1075) can we have it so any image textures with absolute paths are remapped relative as well? ignore the nodetree and other paths from `\\Nexus\assets\BlenderAssets\Amazon\Char\Cartoon1\Cartoon1_006.blend`, those are vestigial. + +--- + +_**Agent (model default, mode Agent)**_ + + + +--- + diff --git a/remap_texture_paths.py b/remap_texture_paths.py index 2c6cebb..a730354 100644 --- a/remap_texture_paths.py +++ b/remap_texture_paths.py @@ -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...")