7
$\begingroup$

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?)

$\endgroup$

2 Answers 2

6
$\begingroup$

Thumbnail extraction via Python

The most current thumbnailer is maintained by ideasman42:

https://github.com/dfelinto/blender-git/blob/master/release/bin/blender-thumbnailer.py

It extracts thumbnail that is stored in a blend file for use with a file manager.

Usage: blender-thumbnailer.py <input.blend> <output.png>

e.g.

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[0].render.resolution_x = 128
bpy.data.scenes[0].render.resolution_y = 128
bpy.data.scenes[0].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\normal and 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)

$\endgroup$
4
  • $\begingroup$ Thanks stacker, I see your code is working. Actually, The word "thumbnail" I mean is the "thumb icon" for .blend itself, like this. $\endgroup$ Commented Jan 16, 2015 at 10:40
  • $\begingroup$ I didn't figure out how to use the blender-thumbnailer.py and I'm not sure if it meets my need here. Could you tell more about it? $\endgroup$ Commented Jan 17, 2015 at 3:24
  • $\begingroup$ @LeonCheung the blender-thumbnailer.py only extracts a png from .blend, saving a loaded file recreates the thumbnail, my last try was to automate this with a script but it didn't recreate the thumbnail. Sorry $\endgroup$
    – stacker
    Commented Jan 17, 2015 at 9:32
  • $\begingroup$ It's OK. Thanks all the same for the nice answer though. It's very inspiring. :) $\endgroup$ Commented Jan 17, 2015 at 10:10
5
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ have you tried to supply '-b' as the first parameter, Blender appears to be picky on parameter order. $\endgroup$
    – stacker
    Commented Jan 17, 2015 at 9:35
  • $\begingroup$ Yes, I tried to tweak with orders, too. :( And btw, my way got a big disadvange. It cannot operate on those files with space in their filenames. I don't know why yet. $\endgroup$ Commented Jan 17, 2015 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .