1.Take the .py script from the code sample below these steps and put it somewhere sensible
The output directories in the file are these, please change to your own:
basedir = 'C:\\Users\\###USERNAME###\\Downloads\\TestBatch' output_base_dir = 'C:\\Users\\###USERNAME###\\Downloads\\TestBatch\\compressed'
In powershell/terminal/command line on windows I ran the below command from this location where my Blender was installed, please change the location of 'blender-batch-gltf-export.py'
to your own location for it.
Location to open powershell from:
'C:\Program Files\Blender Foundation\Blender 3.4'
Command to run (change the location of the script here):
.\blender --background -P C:\Users\###USERNAME###\Downloads\TestBatch\blender-batch-gltf-export.py
- The script can be edited easily if you look at the lines 31 and 39 for
'bpy.ops.export_scene.gltf('
e.g. I can add animations export here via adding 'export_animations=True,'
bpy.ops.export_scene.gltf(
export_animations=True,
export_format='GLB',
export_draco_mesh_compression_enable=True,
filepath=out_path)
You can see documentation on the GLTF export options you can change here, they will match up with those of the Blender GUI export GLTF menu properties:
The script, save as blender-batch-gltf-export.py
:
import bpy
import os
# Blender application is needed
# Script for Windows
# From Blender install folder: .\blender --background -P C:\Users\###USERNAME###Robert.Farthing\Downloads\TestBatch\blender-batch-gltf-export.py
# Edit your own
basedir = 'C:\\Users\\###USERNAME###\\Downloads\\TestBatch'
output_base_dir = 'C:\\Users\\###USERNAME###\\Downloads\\TestBatch\\compressed'
files = [f for f in os.listdir(basedir) if f.endswith('.blend')]
print(f'Found {len(files)} blend files. Processing...')
for f in files:
if not f.endswith('.blend'):
continue
path = os.path.join(basedir, f)
bpy.ops.wm.open_mainfile(filepath=path)
bpy.ops.object.select_all(action='DESELECT')
try:
just_name = f.replace('.blend', '_draco')
out_path = os.path.join(output_base_dir, just_name)
bpy.ops.export_scene.gltf(
export_format='GLB',
export_draco_mesh_compression_enable=True,
filepath=out_path)
except:
just_name = f.replace('.blend', '')
out_path = os.path.join(output_base_dir, just_name)
bpy.ops.export_scene.gltf(
export_format='GLB',
export_draco_mesh_compression_enable=False,
filepath=out_path)