Files
ProjectStructure_HOME/compress_blend_files.bat

86 lines
2.8 KiB
Batchfile
Raw Normal View History

2025-08-11 13:03:09 -06:00
@echo off
setlocal enabledelayedexpansion
echo Starting Blender file compression...
2025-08-15 12:21:45 -06:00
REM Check if files were dragged onto the batch file
if "%~1"=="" (
echo.
echo Usage: Drag .blend files onto this batch file to compress them.
echo Output will be saved to the \output folder.
echo.
pause
exit /b 1
)
REM Create output directory if it doesn't exist
2025-08-11 13:03:09 -06:00
if not exist "output" mkdir "output"
REM Create a temporary Python script for compression
set "TEMP_SCRIPT=compress_blend_temp.py"
echo Creating Python script: !TEMP_SCRIPT!
2025-08-15 12:21:45 -06:00
2025-08-11 13:03:09 -06:00
(
echo import bpy
echo import os
2025-08-15 12:21:45 -06:00
echo import sys
2025-08-11 13:03:09 -06:00
echo.
echo # Enable compression globally
echo bpy.context.preferences.filepaths.save_version = 0
echo bpy.context.preferences.filepaths.use_file_compression = True
echo.
2025-08-15 12:21:45 -06:00
echo # Create output directory if it doesn't exist
2025-08-11 13:03:09 -06:00
echo if not os.path.exists^("output"^):
echo os.makedirs^("output"^)
echo.
2025-08-15 12:21:45 -06:00
echo # Get command line arguments ^(the dragged files^)
echo blend_files = sys.argv[sys.argv.index^("--"^) + 1:] if "--" in sys.argv else []
2025-08-11 13:03:09 -06:00
echo.
echo print^("Found " + str^(len^(blend_files^)^) + " .blend files to compress"^)
echo.
echo for blend_file in blend_files:
2025-08-15 12:21:45 -06:00
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^("Skipping " + blend_file + " ^(already exists in output^)"^)
echo continue
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 except Exception as e:
echo print^("Failed to compress " + blend_file + ": " + str^(e^)^)
echo else:
echo print^("Skipping " + blend_file + " ^(not a .blend file^)"^)
2025-08-11 13:03:09 -06:00
echo.
echo print^("Compression 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
)
2025-08-15 12:21:45 -06:00
REM Run Blender to process the dragged files
echo Processing dragged .blend files...
2025-08-11 13:03:09 -06:00
echo Using script: !TEMP_SCRIPT!
2025-08-15 12:21:45 -06:00
blender --background --factory-startup --python "!TEMP_SCRIPT!" -- %*
2025-08-11 13:03:09 -06:00
REM Clean up temporary script
echo Cleaning up temporary script...
del "!TEMP_SCRIPT!" 2>nul
echo.
echo Done!
pause