From 927aac74ab5fa1326faa33c41b967e550088d5d5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Jun 2010 12:06:30 +0000 Subject: [PATCH] - module for reading blend start/end frames and scene name (useful for finding the total frame count without loading a blend file) - added render api as unstable to the docs. --- release/scripts/modules/blend_render_info.py | 99 ++++++++++++++++++++ source/blender/python/doc/sphinx_doc_gen.py | 1 + 2 files changed, 100 insertions(+) create mode 100755 release/scripts/modules/blend_render_info.py diff --git a/release/scripts/modules/blend_render_info.py b/release/scripts/modules/blend_render_info.py new file mode 100755 index 00000000000..b7018ad6b64 --- /dev/null +++ b/release/scripts/modules/blend_render_info.py @@ -0,0 +1,99 @@ +#!/usr/bin/python + +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +# This module can get render info without running from inside blender. +# +# This struct wont change according to Ton. +# Note that the size differs on 32/64bit +# +# typedef struct BHead { +# int code, len; +# void *old; +# int SDNAnr, nr; +# } BHead; + +def read_blend_rend_chunk(path): + + import struct + + file = open(path, 'rb') + + head = file.read(7) + + if head[0:2] == b'\x1f\x8b': # gzip magic + import gzip + file.close() + file = gzip.open(path, 'rb') + head = file.read(7) + + if head != b'BLENDER': + print("not a blend file:", path) + file.close() + return [] + + is_64_bit = (file.read(1) == b'-') + + # true for PPC, false for X86 + is_big_endian = (file.read(1) == b'V') + + # Now read the bhead chunk!!! + file.read(3) # skip the version + + scenes = [] + + sizeof_bhead = 24 if is_64_bit else 20 + + while file.read(4) == b'REND': + sizeof_bhead_left = sizeof_bhead - 4 + + rend_length = struct.unpack('>i' if is_big_endian else '2i' if is_big_endian else '<2i', file.read(8)) + + scene_name = file.read(24) + + scene_name = scene_name[:scene_name.index(b'\0')] + + try: + scene_name = str(scene_name, 'utf8') + except TypeError: + pass + + scenes.append((start_frame, end_frame, scene_name)) + + return scenes + + +def main(): + import sys + for arg in sys.argv[1:]: + if arg.lower().endswith('.blend'): + for value in read_blend_rend_chunk(arg): + print("%d %d %s" % value) + +if __name__ == '__main__': + main() diff --git a/source/blender/python/doc/sphinx_doc_gen.py b/source/blender/python/doc/sphinx_doc_gen.py index 4640ba4c1ef..3b0b9f60795 100644 --- a/source/blender/python/doc/sphinx_doc_gen.py +++ b/source/blender/python/doc/sphinx_doc_gen.py @@ -331,6 +331,7 @@ def rna2sphinx(BASEPATH): fw(" \n") fw(" The following areas are subject to change.\n") fw(" * operator names and arguments\n") + fw(" * render api\n") fw(" * function calls with the data api (any function calls with values accessed from bpy.data), including functions for importing and exporting meshes\n") fw(" * class registration (Operator, Panels, Menus, Headers)\n") fw(" * modules: bpy.props, blf)\n")