86 lines
2.8 KiB
Batchfile
86 lines
2.8 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
echo Starting Blender file compression...
|
|
|
|
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
|
|
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!
|
|
|
|
(
|
|
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 compress"^)
|
|
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^("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^)"^)
|
|
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
|
|
)
|
|
|
|
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!" -- %*
|
|
|
|
REM Clean up temporary script
|
|
echo Cleaning up temporary script...
|
|
del "!TEMP_SCRIPT!" 2>nul
|
|
|
|
echo.
|
|
echo Done!
|
|
pause |