find missing files slow operator
This commit is contained in:
153
find_missing_files.bat
Normal file
153
find_missing_files.bat
Normal file
@@ -0,0 +1,153 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
echo Starting missing file search...
|
||||
|
||||
REM Check if files were dragged onto the batch file
|
||||
if "%~1"=="" (
|
||||
echo.
|
||||
echo Usage: Drag .blend files onto this batch file to find missing files.
|
||||
echo Output will be saved to the \output folder.
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Create output directory if it doesn't exist
|
||||
if not exist "output" mkdir "output"
|
||||
|
||||
REM Initialize counters and tracking
|
||||
set "processed=0"
|
||||
set "crashed=0"
|
||||
set "skipped=0"
|
||||
set "found_missing=0"
|
||||
set "search_path=A:/1 Amazon_Active_Projects/1 BlenderAssets/Amazon/"
|
||||
|
||||
REM Create a temporary Python script for processing
|
||||
set "TEMP_SCRIPT=find_missing_files_temp.py"
|
||||
echo Creating Python script: !TEMP_SCRIPT!
|
||||
|
||||
(
|
||||
echo import bpy
|
||||
echo import os
|
||||
echo import sys
|
||||
echo.
|
||||
echo # Enable compression globally
|
||||
echo bpy.context.preferences.filepaths.save_version = 0
|
||||
echo bpy.context.preferences.filepaths.use_file_compression = True
|
||||
echo.
|
||||
echo # Create output directory if it doesn't exist
|
||||
echo if not os.path.exists^("output"^):
|
||||
echo os.makedirs^("output"^)
|
||||
echo.
|
||||
echo # Get command line arguments ^(the dragged files^)
|
||||
echo blend_files = sys.argv[sys.argv.index^("--"^) + 1:] if "--" in sys.argv else []
|
||||
echo.
|
||||
echo print^("Found " + str^(len^(blend_files^)^) + " .blend files to process"^)
|
||||
echo.
|
||||
echo for blend_file in blend_files:
|
||||
echo ^ if blend_file.lower^(^).endswith^(".blend"^):
|
||||
echo ^ try:
|
||||
echo ^ # Create output path in output folder
|
||||
echo ^ filename = os.path.basename^(blend_file^)
|
||||
echo ^ output_file = os.path.join^("output", filename^)
|
||||
echo ^ # Check if output file already exists
|
||||
echo ^ if os.path.exists^(output_file^):
|
||||
echo ^ print^("SKIP_EXISTING:" + blend_file^)
|
||||
echo ^ continue
|
||||
echo ^ print^("PROCESSING:" + blend_file^)
|
||||
echo ^ # Load the blend file
|
||||
echo ^ bpy.ops.wm.open_mainfile^(filepath=blend_file^)
|
||||
echo ^ # Count missing files before search
|
||||
echo ^ missing_before = len^([f for f in bpy.data.images if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
|
||||
echo ^ missing_before += len^([f for f in bpy.data.movieclips if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
|
||||
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!", 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^)^)^]^)
|
||||
echo ^ missing_after += len^([f for f in bpy.data.movieclips if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
|
||||
echo ^ missing_after += len^([f for f in bpy.data.sounds if not f.filepath or not os.path.exists^(bpy.path.abspath^(f.filepath^)^)^]^)
|
||||
echo ^ found_count = missing_before - missing_after
|
||||
echo ^ print^("FOUND_MISSING:" + blend_file + ":" + str^(found_count^)^)
|
||||
echo ^ # Save to output folder
|
||||
echo ^ bpy.ops.wm.save_mainfile^(filepath=output_file, compress=True^)
|
||||
echo ^ print^("SUCCESS:" + blend_file + ":" + output_file^)
|
||||
echo ^ except Exception as e:
|
||||
echo ^ print^("CRASH:" + blend_file + ":" + str^(e^)^)
|
||||
echo ^ else:
|
||||
echo ^ print^("SKIP_NOT_BLEND:" + blend_file^)
|
||||
echo.
|
||||
echo print^("MISSING_FILE_SEARCH_COMPLETE"^)
|
||||
echo bpy.ops.wm.quit_blender^(^)
|
||||
) > "!TEMP_SCRIPT!"
|
||||
|
||||
REM Check if script was created successfully
|
||||
if exist "!TEMP_SCRIPT!" (
|
||||
echo Script created successfully: !TEMP_SCRIPT!
|
||||
) else (
|
||||
echo ERROR: Failed to create script file!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Run Blender to process the dragged files
|
||||
echo Processing dragged .blend files...
|
||||
echo Using script: !TEMP_SCRIPT!
|
||||
echo Search path: !search_path!
|
||||
blender --background --factory-startup --python "!TEMP_SCRIPT!" -- %* 2^>^&1 | powershell -NoProfile -Command "$input | Tee-Object -FilePath 'blender_output.txt'"
|
||||
|
||||
REM Clean up temporary script
|
||||
echo Cleaning up temporary script...
|
||||
del "!TEMP_SCRIPT!" 2>nul
|
||||
|
||||
REM Parse output and generate report
|
||||
echo.
|
||||
echo ========================================
|
||||
echo MISSING FILE SEARCH REPORT
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
REM Track found missing files during parse
|
||||
for /f "tokens=1,2,3 delims=:" %%a in (blender_output.txt) do (
|
||||
if "%%a"=="SUCCESS" (
|
||||
set /a processed+=1
|
||||
echo [!processed!] SUCCESS: %%b
|
||||
echo Saved to: %%c
|
||||
echo.
|
||||
) else if "%%a"=="CRASH" (
|
||||
set /a crashed+=1
|
||||
echo [!crashed!] CRASHED: %%b
|
||||
echo Error: %%c
|
||||
echo.
|
||||
) else if "%%a"=="SKIP_EXISTING" (
|
||||
set /a skipped+=1
|
||||
echo [!skipped!] SKIPPED ^(already exists^): %%b
|
||||
echo.
|
||||
) else if "%%a"=="SKIP_NOT_BLEND" (
|
||||
set /a skipped+=1
|
||||
echo [!skipped!] SKIPPED ^(not .blend^): %%b
|
||||
echo.
|
||||
) else if "%%a"=="FOUND_MISSING" (
|
||||
for /f "delims= tokens=1" %%x in ("%%c") do set "found_in_file=%%x"
|
||||
set /a found_missing+=found_in_file
|
||||
echo Found missing files: !found_in_file!
|
||||
)
|
||||
)
|
||||
|
||||
REM Clean up output file
|
||||
del /f /q "blender_output.txt" 2>nul
|
||||
|
||||
echo ========================================
|
||||
echo SUMMARY
|
||||
echo ========================================
|
||||
echo Processed: !processed! files
|
||||
echo Crashed: !crashed! files
|
||||
echo Skipped: !skipped! files
|
||||
echo Total missing files found: !found_missing!
|
||||
echo Search path: !search_path!
|
||||
echo Total: %* files
|
||||
echo ========================================
|
||||
echo.
|
||||
echo Done!
|
||||
pause
|
||||
Reference in New Issue
Block a user