@echo off setlocal enabledelayedexpansion echo Starting Blender file compression... REM Create input and output directories if they don't exist if not exist "input" mkdir "input" 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 glob 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 input and output directories if they don't exist echo if not os.path.exists^("input"^): echo os.makedirs^("input"^) echo if not os.path.exists^("output"^): echo os.makedirs^("output"^) echo. echo # Get all .blend files in input directory echo blend_files = glob.glob^("input/*.blend"^) echo. echo print^("Found " + str^(len^(blend_files^)^) + " .blend files to compress"^) echo. echo for blend_file in blend_files: 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. 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 once to process all files echo Processing all .blend files in a single Blender instance... 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