2
$\begingroup$

I'd like to be able to use an external instance of Python (ie. not Blender's internal python) to read a blend file and inspect it for Render Settings (ie. Start Frame, etc.).

Is this possible without firing up the Blender app itself? I don't want to have to depend on a Blender app, or to import the bpy module because the main project is in Python 2.7.

Also, I'd like to avoid any cli calls to blender to get this information.

$\endgroup$
7
  • $\begingroup$ I believe not, but from the source code of blender it is possible to compile a only a standalone bpy. IT can do the trick for you. $\endgroup$
    – Mörkö
    Commented Sep 16, 2015 at 5:54
  • $\begingroup$ Looks like it is possible by inspecting the file on a byte level, and by knowing the byte address of the specific data value that you want. More info here: atmind.nl/blender/mystery_ot_blend.html. Once I figure out the specifics I'll post more. $\endgroup$ Commented Sep 16, 2015 at 6:23
  • 5
    $\begingroup$ Check out blender.stackexchange.com/questions/3141/… $\endgroup$
    – batFINGER
    Commented Sep 16, 2015 at 12:48
  • $\begingroup$ What settings do you need? - (ie. Start Frame, etc.). is too vague. $\endgroup$
    – ideasman42
    Commented Sep 16, 2015 at 17:27
  • $\begingroup$ I'd be happy with Start Frame, End Frame, and output File Format to begin with. $\endgroup$ Commented Sep 16, 2015 at 18:16

2 Answers 2

4
$\begingroup$

While it is possible, using blender will be much easier. A small script that you pass to blender when run from a cli is small and easy to maintain. From another python script you could automate it with -

from subprocess import call
call(['blender','-b','file.blend','-P','script.py'])

You can even have your script generate the small temporary script that gets passed to blender.

However if you really have a need to not require blender to be installed, you may want to look at an old project that appears to have died off called blender-aid, it provided a web interface to blend files and used a python script to access data in the blend file, it was intended to assist project management and allowed file links to be repaired and/or re-factored, so apart from reading a blend file it could also write changes to them. While the full info of reading a blend file is contained within blender's source code, you may be able to get a start with blender-aid's old script here - or at least it will give you an idea of how much code is needed.

$\endgroup$
3
  • $\begingroup$ The blendarid tip was great! I'm thinking that will help me find the solution. Thanks. $\endgroup$ Commented Sep 16, 2015 at 18:29
  • $\begingroup$ @sambler The old script link is dead, I've tried to find it... there is a trunk folder at google code, but I was not sure. $\endgroup$
    – p2or
    Commented Sep 17, 2015 at 12:25
  • $\begingroup$ @poor My bad, I pasted the wrong link. Yes, the blender-aid svn repo is at google code. $\endgroup$
    – sambler
    Commented Sep 17, 2015 at 13:16
2
$\begingroup$

I've found a solution that works the way I need for my project. A big thank you to sambler for pointing me in the right direction towards the blenderaid project which allowed me to get the results I needed.

Here's how I did it:

  1. I downloaded the blender aid package, renamed the folder from "blenderaid-py-20110211-2" to just "blenderaid" and placed the folder in the /lib folder of my project
  2. I added init.py files to the /lib and /lib/blenderaid folders
  3. In my root folder I created a test.py file with the following code:

Update - I discovered that the block label for finding image type changed at Blender 2.61 - I updated code to add the if/then statement


import os
from lib.blenderaid.blendfile import *


TRANS=[
    "TGA", "IRIS", "HAMX", "FTYPE", "JPEG", "MOV", "UNKOWN", "IRIZ", "UNKOWN", "UNKOWN", "UNKOWN", "UNKOWN", "UNKOWN", "UNKOWN", "TGA", "AVI", "AVI", "PNG", "AVI", "MOV", "BMP", "HDR", "TIFF",
    "EXR", "FFMPEG", "FRAMESERVER", "CINEON", "DPX", "MULTILAYER", "DDS"
]

def formatImageType(value):
    if value<len(TRANS):
        return TRANS[value]
    else:
        return "UNKNOWN"


file = 'path/to/file.blend'


if file.endswith(".blend"):
    bf=openBlendFile(file)

    for block in bf.FindBlendFileBlocksWithCode("SC"):

        scStartFrame = block.Get("r.sfra");
        scEndFrame = block.Get("r.efra");
        scImageType = formatImageType(block.Get("r.imtype"))

        if bf.Header.Version>=261:
            scImageType = formatImageType(ord(block.Get("r.im_format.imtype")))
        else:
            scImageType = formatImageType(block.Get("r.imtype"))

    print scStartFrame, scEndFrame, scImageType
$\endgroup$
3
  • $\begingroup$ Hey @ToddMcIntosh do you still have a copy of blenderaid? If so, could you upload it somewhere? Thanks in advance. $\endgroup$
    – Teck-freak
    Commented May 7, 2017 at 9:41
  • $\begingroup$ Can you not just download it from the repo I linked above? $\endgroup$ Commented May 7, 2017 at 13:25
  • $\begingroup$ Weird! Wenn I was on that repository, it claimed an 404. Well, just went there again to double-check and there it was. . . Anyways, thanks mate. $\endgroup$
    – Teck-freak
    Commented May 10, 2017 at 15:01

You must log in to answer this question.

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