make draggable

This commit is contained in:
Nathan
2025-08-15 12:21:45 -06:00
parent e79878e656
commit 51ce499390
2 changed files with 295 additions and 27 deletions

View File

@@ -3,50 +3,61 @@ setlocal enabledelayedexpansion
echo Starting Blender file compression...
REM Create input and output directories if they don't exist
if not exist "input" mkdir "input"
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 glob
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 input and output directories if they don't exist
echo if not os.path.exists^("input"^):
echo os.makedirs^("input"^)
echo # Create output directory if it doesn't exist
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 # 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 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 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^(^)
@@ -61,10 +72,10 @@ if exist "!TEMP_SCRIPT!" (
exit /b 1
)
REM Run Blender once to process all files
echo Processing all .blend files in a single Blender instance...
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!" -- %*
REM Clean up temporary script
echo Cleaning up temporary script...