blender crash handling
This commit is contained in:
@@ -16,6 +16,11 @@ if "%~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"
|
||||
|
||||
REM Create a temporary Python script for compression
|
||||
set "TEMP_SCRIPT=compress_blend_temp.py"
|
||||
echo Creating Python script: !TEMP_SCRIPT!
|
||||
@@ -46,20 +51,20 @@ 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^("Skipping " + blend_file + " ^(already exists in output^)"^)
|
||||
echo print^("SKIP_EXISTING:" + blend_file^)
|
||||
echo continue
|
||||
echo print^("Processing: " + blend_file^)
|
||||
echo print^("PROCESSING:" + blend_file^)
|
||||
echo # Load the blend file
|
||||
echo bpy.ops.wm.open_mainfile^(filepath=blend_file^)
|
||||
echo # Save with compression to output folder
|
||||
echo bpy.ops.wm.save_mainfile^(filepath=output_file, compress=True^)
|
||||
echo print^("Successfully compressed: " + blend_file + " -^> " + output_file^)
|
||||
echo print^("SUCCESS:" + blend_file + ":" + output_file^)
|
||||
echo except Exception as e:
|
||||
echo print^("Failed to compress " + blend_file + ": " + str^(e^)^)
|
||||
echo print^("CRASH:" + blend_file + ":" + str^(e^)^)
|
||||
echo else:
|
||||
echo print^("Skipping " + blend_file + " ^(not a .blend file^)"^)
|
||||
echo print^("SKIP_NOT_BLEND:" + blend_file^)
|
||||
echo.
|
||||
echo print^("Compression complete!"^)
|
||||
echo print^("COMPRESSION_COMPLETE"^)
|
||||
echo bpy.ops.wm.quit_blender^(^)
|
||||
) > "!TEMP_SCRIPT!"
|
||||
|
||||
@@ -75,12 +80,63 @@ if exist "!TEMP_SCRIPT!" (
|
||||
REM Run Blender to process the dragged files
|
||||
echo Processing dragged .blend files...
|
||||
echo Using script: !TEMP_SCRIPT!
|
||||
blender --background --factory-startup --python "!TEMP_SCRIPT!" -- %*
|
||||
blender --background --factory-startup --python "!TEMP_SCRIPT!" -- %* > blender_output.txt 2^>^&1
|
||||
|
||||
REM Clean up temporary script
|
||||
echo Cleaning up temporary script...
|
||||
del "!TEMP_SCRIPT!" 2>nul
|
||||
|
||||
REM Parse output and generate report
|
||||
echo.
|
||||
echo ========================================
|
||||
echo COMPRESSION REPORT
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
REM Count processed files and get file info
|
||||
for /f "tokens=1,2,3 delims=:" %%a in (blender_output.txt) do (
|
||||
if "%%a"=="SUCCESS" (
|
||||
set /a processed+=1
|
||||
set "original_file=%%b"
|
||||
set "compressed_file=%%c"
|
||||
|
||||
REM Get file sizes
|
||||
for %%f in ("!original_file!") do set "original_size=%%~zf"
|
||||
for %%f in ("!compressed_file!") do set "compressed_size=%%~zf"
|
||||
|
||||
echo [!processed!] !original_file!
|
||||
echo Original: !original_size! bytes
|
||||
echo Compressed: !compressed_size! bytes
|
||||
set /a "savings=!original_size! - !compressed_size!"
|
||||
echo Savings: !savings! bytes
|
||||
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.
|
||||
)
|
||||
)
|
||||
|
||||
REM Clean up output file
|
||||
del "blender_output.txt" 2>nul
|
||||
|
||||
echo ========================================
|
||||
echo SUMMARY
|
||||
echo ========================================
|
||||
echo Processed: !processed! files
|
||||
echo Crashed: !crashed! files
|
||||
echo Skipped: !skipped! files
|
||||
echo Total: %* files
|
||||
echo ========================================
|
||||
echo.
|
||||
echo Done!
|
||||
pause
|
||||
Reference in New Issue
Block a user