I got hundreds of old files (some are from 2.4x) that need to generate Preview/thumbnail images with the new Blender version. I think the straightforward way is to open and save each files to generate, which is quite inefficient. So I'm wondering a quicker way to do this automatically. (via a command line or bat file?)
Thumbnail extraction via Python
The most current thumbnailer is maintained by ideasman42:
It extracts thumbnail that is stored in a blend file for use with a file manager.
blender-thumbnailer.py <input.blend> <output.png>
python blender-thumbnailer.py test.blend test.png
Batch rendering via command line
Alternatively you could batch process the .blend files from a .bat file:
for %%f in (*.blend) do ( blender %%~nf.blend -b -o //%%~nf -F PNG -x 1 -f 1 )
See also the documentation of command line parameters.
In order to set a fixed thumbnail size you would (probably) invoke a python script (-P script_name.py) that sets the render size.
Something like this size.py (didn't work for me):
import bpy bpy.data.scenes.render.resolution_x = 128 bpy.data.scenes.render.resolution_y = 128 bpy.data.scenes.render.resolution_percentage = 100
In Blenders installation directory is a file "BlendThumb64.dll" which is registered during installation or
C:\Program Files\Blender Foundation\Blender>blender -R Registering file extension...success (user)
Running as administrator would register .blend for all users.
I'm not sure whether this is related: In
C:\Users\<username>\.thumbnails\fail\blender you can find created (or failed) thumbnails.
Load, render and save
import bpy import os filepath = bpy.data.filepath directory = os.path.dirname(filepath) image_path = os.path.join( directory , "image.png") bpy.data.scenes['Scene'].render.filepath = image_path bpy.ops.render.render( write_still=True ) print("file %s" % filepath ) bpy.ops.wm.save_as_mainfile(filepath=filepath)
blender -b test.blend -P save.py (above script, didn't recreate the embedded thumbnail)
Inspired by stacker's answer:
I built two files, one is a save_prev.py file:
import bpy bpy.ops.wm.save_mainfile() bpy.ops.wm.quit_blender()
Another one is a .bat file:
for %%f in (*.blend) do ( <blender_install_path> %%~nf.blend -P save_prev.py )
For example, if I installed the official Blender (for Windows) all by default, then it may be like this:
for %%f in (*.blend) do ( C:\PROGRA~1\BLENDE~1\Blender\blender %%~nf.blend -P save_prev.py )
Then, put these two files into the same folder containing all the old files, run .bat.
I found that
-b parameter appears not working in this case. That is why I have to open, save and close each file by a separate save_prev.py. Not so effective, I know, but it saves a lot of manual work more or less.
The result is exactly what I want, but I still appreciate any better idea to do this.