Is there a way to get render info (frame start/end, output path, etc.) from a .blend file without actually running Blender?

I know it's possible to launch Blender and run a Python expression to extract information. However, this requires additional processing (grep, sed, etc... see here for reference) and could be a bit heavy and time consuming for large .blend files.

  • 1
    $\begingroup$ Don't think this is possible as blend files are binary. What about running blender from the command line to just open the blendfile, print out the settings you want and close? $\endgroup$ – TLousky Jun 9 '16 at 13:57
  • $\begingroup$ That's basically what I'm doing in the script that I link to in the question. I was seeing if there's another way to approach it. And I think I have my answer. $\endgroup$ – Fweeb Jun 9 '16 at 14:39

There are 2 ways to do this, both of these scripts are distributed with Blender, but can be used outside of Blender, and involve reading the file using Python.

Using blend_render_info.py

Extract information from the header, Blender writes the: Scene name, start-frame, end-frame into the file header in a way that can be extracted without reading the entire file.

You can test this from within Blender, assuming you have a file loaded:

import blend_render_info

import bpy
filepath = bpy.data.filepath

data = blend_render_info.read_blend_rend_chunk(filepath)
for frame_start, frame_end, scene_name in data:
    print(frame_start, frame_end, scene_name)

The module blend_render_info.py comes with Blender (included under 2.77/scripts/modules/blend_render_info.py). And is a single-file Python module that can also be run directly, eg:


python 2.77/scripts/modules/blend_render_info.py /path/to/test.blend

Outputs for example:

1 250 Scene

Using blendfile.py

This is a single-file Python module which implements a full blend file reader/writer. This means you can do access any information you like, however doing so is more involved, as well as being slower since its needs to read the blend file - not just the header (although it will still be much faster then loading Blender, then the file).

This is an example of a script that prints scene frame, name and unlike the previous example, the output path.

#!/usr/bin/env python3
This takes a blend file argument and prints out some of its details, eg:

  blend_info.py /path/to/test.blend
import blendfile
import sys

filepath = sys.argv[-1]
with blendfile.open_blend(filepath) as blend:
    scenes = [b for b in blend.blocks if b.code == b'SC']
    for scene in scenes:
        name =          scene[b'id', b'name'][2:].decode('utf-8')
        path =          scene[b'r', b'pic'].decode('utf-8')
        frame_start =   scene[b'r', b'sfra']
        frame_end =     scene[b'r', b'efra']

        print(frame_start, frame_end, repr(name), repr(path))

Example output:

1 250 'Scene' '//'

Note: if you want to extract other info, you can use the Python interactive prompt, and call block.keys() to see which members are available. All keys are bytes, not strings, so take care not to mix this up. This API is currently not documented, but the script is not so huge, for now you have to read the code to see whats possible.

| improve this answer | |
  • $\begingroup$ Thanks! Aside from the code in these scripts that you've linked to, is there any further documentation (like in the Blender manual or the wiki) on their use? $\endgroup$ – Fweeb Jun 9 '16 at 14:45
  • 1
    $\begingroup$ As far as I'm aware this is entirely undocumented, both tools were written for some spesific use cases, and not something exposed to users. However I suppose they could be documented in a subsection of blender.org/manual/advanced/index.html (Maybe call it "Blend File Access"?) $\endgroup$ – ideasman42 Jun 9 '16 at 14:59
  • 1
    $\begingroup$ Wow. that b'r' and b'efra' are some serious secret handshakes. God help the noob who wants to extract the location of a named object. Where in the source would you go to figure out that b'efra' is the thing you want? $\endgroup$ – Mutant Bob Jun 10 '16 at 15:37
  • 1
    $\begingroup$ See structure definitions in: developer.blender.org/diffusion/B/browse/master/source/blender/… In the case of efra - developer.blender.org/diffusion/B/browse/master/source/blender/… $\endgroup$ – ideasman42 Jun 11 '16 at 3:57
  • 1
    $\begingroup$ Running import blendfile from Blender's python console fails for me and says 'No module named 'blendfile'. Can this not be imported from within blender like this? $\endgroup$ – Ray Mairlot Jul 16 '16 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.