find missing files slow operator

This commit is contained in:
Nathan
2025-09-10 16:40:39 -06:00
parent fc4a5b773f
commit eb58d45e03
2 changed files with 405 additions and 1 deletions

View File

@@ -810,7 +810,258 @@ why would I want to recreate an empty file? I don't want the txt to exist.
_**Assistant**_
You're rig
You're right - I'll remove the empty file creation and just delete `blender_output.txt` completely.
---
<details><summary>Edit file: a:\1 Amazon_Active_Projects\3 ProjectStructure\compress_blend_files.bat</summary>
undefined
**Chunk 1**
Lines added: undefined, lines removed: 1
```diff
@@ -138,5 +138,4 @@
REM Clean up output file
del /f /q "blender_output.txt" 2>nul
- type nul > "blender_output.txt"
echo ========================================
```
</details>
---
<details><summary>Edit file: a:\1 Amazon_Active_Projects\3 ProjectStructure\remove_action_fake_users.bat</summary>
undefined
**Chunk 1**
Lines added: undefined, lines removed: 1
```diff
@@ -143,5 +143,4 @@
REM Clean up output file
del /f /q "blender_output.txt" 2>nul
- type nul > "blender_output.txt"
echo ========================================
```
</details>
---
Fixed - both scripts now just delete `blender_output.txt` completely without recreating it.
---
_**User (2025-09-10 17:19Z)**_
now let's create another one that runs the same operator as File > External Data > Find missing files, searching in the path `A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\`
---
_**Assistant**_
I'll create a new batch script that opens each dragged `.blend` file and runs Blender's "Find Missing Files" operator to search for missing assets in the specified Amazon assets directory.
---
---
Created `find_missing_files.bat` that:
- Opens each dragged `.blend` file
- Runs `bpy.ops.file.find_missing_files()` with search path `A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\`
- Counts missing files before/after to track how many were found
- Saves processed files to `output` folder with compression
- Reports total missing files found across all processed files
- Shows live Blender output while logging to file
Drag `.blend` files onto the script to run it.
---
_**User (2025-09-10 17:19Z)**_
Nothing was saved. Let's be sure we're using the correct operator.
Starting missing file search...
Creating Python script: find_missing_files_temp.py
Script created successfully: find_missing_files_temp.py
Processing dragged .blend files...
Using script: find_missing_files_temp.py
Search path: A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\
File "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\find_missing_files_temp.py", line 36
bpy.ops.file.find_missing_files(directory="A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\")
^
SyntaxError: unterminated string literal (detected at line 36)
Blender 4.5.3 LTS (hash 67807e1800cc built 2025-09-09 01:33:33)
Warning: 'Submenu' does not contain '_MT_' with prefix and suffix
Warning: 'Submenu2' does not contain '_MT_' with prefix and suffix
Warning: 'Submenu3' does not contain '_MT_' with prefix and suffix
Warning: 'view3D.Pie_menu' does not contain '_MT_' with prefix and suffix
Warning: 'CustomPanel' does not contain '_PT_' with prefix and suffix
Warning: 'view3D.Quad_menu' does not contain '_MT_' with prefix and suffix
Warning: 'Special_Tools_Menu' does not contain '_MT_' with prefix and suffix
Warning! 'C:\\Program Files\\Blender Foundation\\Blender 4.5\\4.5\\scripts\\startup\\fa_hotkeys.py' has no register function, this is now a requirement for registerable scripts
register_class(...):
Warning: 'Submenu' does not contain '_MT_' with prefix and suffix
register_class(...):
Warning: 'Submenu2' does not contain '_MT_' with prefix and suffix
register_class(...):
Warning: 'Submenu3' does not contain '_MT_' with prefix and suffix
register_class(...):
Warning: 'view3D.Pie_menu' does not contain '_MT_' with prefix and suffix
register_class(...):
Warning: 'CustomPanel' does not contain '_PT_' with prefix and suffix
register_class(...):
Warning: 'view3D.Quad_menu' does not contain '_MT_' with prefix and suffix
register_class(...):
Warning: 'Special_Tools_Menu' does not contain '_MT_' with prefix and suffix
Blender quit
Cleaning up temporary script...
========================================
MISSING FILE SEARCH REPORT
========================================
========================================
SUMMARY
========================================
Processed: 0 files
Crashed: 0 files
Skipped: 0 files
Total missing files found: 0
Search path: A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\
Total: "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 5B.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 2B.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 4.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 3.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 8b.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7_Part1.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 1A.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 6.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 2A.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 5A.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7_Part2.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 9A.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 8c.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 9B.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7a.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7c1.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7c.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7c2.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 9.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7d.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 8a.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 7b.blend" "A:\1 Amazon_Active_Projects\250903_Ambassador_Safety_School\Blends\animations\Manual Stow\AMB_SS_Manual Stow_ani 1.blend" files
========================================
Done
Press any key to continue . . .
---
_**Assistant**_
<think><details><summary>Thought Process</summary>**Fixing the script issue**
I need to address the script find_missing_files.bat since it failed due to string quoting and possibly the wrong operator. The Blender operator for this is bpy.ops.file.find_missing_files. I want to recall the correct API details for Blender versions 3.x and 4.x. I remember the parameters for this operator include a directory and a boolean find_all. The directory should be an absolute path with a trailing slash, and I also need to consider path quoting for Windows.
**Resolving string issues**
Im working on echoing a line from batch into Python, specifically using the operator bpy.ops.file.find_missing_files with a directory path. The challenge is that a raw string in Python can't end with a single backslash, as this escapes the quote. To avoid this, I should ensure the path ends with a double backslash or use forward slashes instead. Another option is to use a normal string with escaped backslashes. I'll also need to double escape backslashes to avoid any confusion in the Python interpreter.
**Transforming path variables**
I can adjust the variable to replace backslashes with double backslashes before writing in the batch file. Alternatively, I could avoid using the variable in Python and construct the directory path with os.path.normpath using forward slashes or triple quotes with doubled backslashes. The easiest approach is to ensure the search_path variable uses forward slashes, like setting it as A:/1 Amazon_Active_Projects/1 BlenderAssets/Amazon/. This way, I'll avoid complications with backslashes in Python, and it should work just fine with Blender's path functions.
**Updating path handling**
I could use doubled backslashes in the search_path variable, like setting it as A:\\1 Amazon_Active_Projects\\1 BlenderAssets\\Amazon\\, but in batch, double backslashes reduce to single ones when echoed. Instead, I think it's easier to just set the search_path as A:/1 Amazon_Active_Projects/1 BlenderAssets/Amazon/ using forward slashes. Then, I can modify my Python call accordingly. Also, I'll need to address the issue with the previous script crashing due to an unterminated string in the "for" loop, so it should work fine after the fixes.
**Ensuring correct operator usage**
I need to verify that the operator is correct: it should be bpy.ops.file.find_missing_files with directory and find_all parameters. The UI for "Find Missing Files" uses directory and can optionally search deeper with find_all=True. I'll make sure to include this to capture all linked libraries and data blocks.
I'll update the batch file to set the search path using forward slashes. After making these changes, I'll also add a debug print statement and keep the output streaming. Lastly, Ill communicate these updates to the user for clarity and encourage them to try again.</details></think>
---
I'll fix the Python string path by switching the search path to forward slashes (avoids backslash-escape issues) and set the operator to use find_all=True. Then I'll update the script.
---
Read file: undefined
---
<think><details><summary>Thought Process</summary>**Updating file paths and operators**
I need to normalize file paths using either `os.path.normpath` or simply replace backslashes with forward slashes. So, Ill update the `search_path` to have forward slashes with the correct directory format. I'll also ensure spaces are properly handled.
Currently, the `search_path` variable is set with backslashes, but Ill change it to forward slashes. Ill also confirm the Blender operators for finding missing files like `bpy.ops.file.find_missing_files`, ensuring to set the parameters correctly for searching directories recursively if needed.
**Verifying properties and settings**
I think the property name I'm looking for is either 'use_recursive' or 'recursive'. I need to confirm that without web access. I've used `bpy.ops.file.find_missing_files(directory="//", find_all=True)`, and I see 'directory' is a required property. Adding 'find_all=True' is helpful for ensuring files are found, but Im not completely sure if the default is recursive.
Additionally, Ill need to save the output only when `found_count > 0`. The user mentioned a script crash that prevented saving, so Ill check if the search path is normalized properly in Python. Lastly, I might want to adjust how we handle existing files when parsing the output.
**Implementing path changes and updates**
Ill need to skip existing items, just like in previous scripts, and implement a path change while adding `find_all=True`. Ive noted the file compression setting, which is fine.
Before any tool calls, Ill provide a status update with minimal text but include necessary updates. I also need to remember to escape parentheses in batch ECHO lines.
Additionally, we should count missing elements in linked data and set the `search_path` variable to forward slashes. Ill make sure to delete `blender_output.txt` at the end. Lets proceed with the implementation!</details></think>
---
I'll update the search path to use forward slashes to avoid Python escape issues and add find_all=True to the operator, then re-run.
---
<details><summary>Edit file: a:\1 Amazon_Active_Projects\3 ProjectStructure\find_missing_files.bat</summary>
undefined
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -22,5 +22,5 @@
set "skipped=0"
set "found_missing=0"
- set "search_path=A:\1 Amazon_Active_Projects\1 BlenderAssets\Amazon\"
+ set "search_path=A:/1 Amazon_Active_Projects/1 BlenderAssets/Amazon/"
REM Create a temporary Python script for processing
```
**Chunk 2**
Lines added: 1, lines removed: 1
```diff
@@ -64,5 +64,5 @@
echo ^ missing_before += len^([f for f in bpy.data.sounds if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
echo ^ # Run find missing files operator
- echo ^ bpy.ops.file.find_missing_files^(directory="!search_path!"^)
+ echo ^ bpy.ops.file.find_missing_files^(directory="!search_path!", find_all=True^)
echo ^ # Count missing files after search
echo ^ missing_after = len^([f for f in bpy.data.images if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
```
</details>
---
<think><details><summary>Thought Process</summary>**Evaluating file operators in Blender**
I need to give a clear answer regarding the Python SyntaxError the user faced due to backslashes in their string. I suggested using forward slashes and updating the script with `find_all=True`. In Blender, the operator for finding missing files is `bpy.ops.file.find_missing_files(directory="", find_all=False)`. Ill check the documentation to confirm the parameters for this operator and ensure everything is correctly set up, especially regarding how the batch file writes the directory string with the environment variable. It sounds good to use forward slashes to avoid escape issues!
**Fixing processing issues**
The report indicates that 0 files were processed because Python crashed before the loop began. We changed the operator call and the path, but I need to ensure that the properties for images, movie clips, and sounds all have an existing 'filepath.' The counting logic should be fine, and we saved to the 'output' folder in compressed format, but the user noted that nothing was saved due to the earlier crash. Ill double-check that `bpy.context.preferences.filepaths.use_file_compression = True` is set correctly and address potential issues with variable expansion in the batch file when using `!search_path!`.
**Clarifying escaping in code**
I need to think through the use of parentheses and quotes in my code. It seems I used `^` to escape parentheses, and for the Python string, I employed double quotes while escaping them with `\"`. However, during the `echo` command, I mistakenly wrote `\"` without proper escaping. Ive noticed there's a standard for including parentheses with `^(` and `^)` while quotes dont require backslashes — they just use double quotes directly. For example, `echo bpy.ops.wm.save_mainfile^(filepath=output_file, compress=True^)` works fine without wrapping in extra quotes. I'll make sure the new line with `directory=\"!search_path!\"` aligns with these conventions.
**Understanding quoting in echo commands**
Im noticing how they typically used quotes in their echo command, like in `echo blend_files = sys.argv[sys.argv.index^("--"^) + 1:]`. They included `--` within quotes and escaped those with `^("--"^)`. For our directory string, I can follow this pattern: using `directory="A:/..."` doesn't need quote escaping for echo. In batch scripts, the echo command treats quotes as part of the text, so I can include them directly. However, adding backslashes before quotes might create extra backslashes in the Python code, which isnt necessary. I think the earlier error came from Python misinterpreting `\1` as an escape sequence.
**Finalizing the response**
Ive been going over the issue where the backslash followed by '1' isn't a valid escape in Python. Generally, an unterminated string error happens when there's an unescaped backslash at the end or mismatched quotes. The error likely relates to using forward slashes, which Ive updated in the script. We confirmed that the operator `bpy.ops.file.find_missing_files(directory=..., find_all=True)` requires an absolute path ending with a slash. Ill respond to the user by confirming that we fixed the path quoting, included forward slashes, and insist it now saves to output. If issues persist, I might mention adding `report='INVOKE_DEFAULT'`, though that may not apply here.</details></think>
---
- Fixed: updated `find_missing_files.bat` to use forward slashes in the search path and call the correct operator: `bpy.ops.file.find_missing_files(directory="A:/1 Amazon_Active_Projects/1 BlenderAssets/Amazon/", find_all=True)`.
- It now should open each `.blend`, search that directory for missing assets, then save a compressed copy to `output`.
Try dragging the same `.blend` files onto `find_missing_files.bat` again. If any still dont save, paste the new console output and Ill adjust.
---