# Is there a way to acces external .blend file's data with python script?

I'm writing an addon to parse a directory (and its sub-dirs) to write an XML file which describe the tree-structure of the assets contained in that directory.
At the moment, my standalone script works pretty well.

The fact is, I need to add some info to the XML, like the dependencies (linked libraries) of each .blend file the script found.

I found a way to do this (outside blender), with the module "pyblenderfile" : http://code.google.com/p/pyblenderfile/

The principle of this module is to open a .blend and get all its data. But it's pretty long and often buggy on large .blend files. Especially since it's included in a for ... loop!

So I wonder if there is a utility function or method into Blender API, to access other .blend files data (without having to wm.open() them) ?

There's no data API for the .blend file format.

However, it sounds like you're trying to make a tool similar to Blender-Aid (code is here). Perhaps that's better place to start.

Note that blendfile.py from Blender-Aid can be used as a standalone blend file reader.

Yes, you can load in blend file data without opening the blend file using the library API.

Though this is intended for linking in data, you can use it to get data-blocks from a blend file. However it may not be a solution for you since you can only list the data-block names.

Optionally you could link the data, then remove it if you wanted to find out more about the data-blocks.

Note, I realize that blendfile.py may prove a better solution regarding the use case described in the question, but adding this answer for completeness, others who read this question may find the library method useful.

• Thanks @ideasman42, the blendfile.py script did the job pretty well (I had a little issue with "string length" while reading blocks, but I found a workaround and everything works perfect) – Polosson Aug 17 '13 at 13:30
• @Polosson, I noticed string length needed changes too, would be good to get these updated committed back to the original repo. – ideasman42 Aug 17 '13 at 13:35
• well, I made a very small modif in the blendfile.py... Just increased the range (line 122), up to 1250. It prevent the use of FindBlendFileBlocksWithCode(), then block.Get() to raise the list index out of range exception, but it return some strange strings, like link1.blendnk1.blend, instead of link1.blend. So my workaround was to split the string to only get the first :.blend string! Not very neat but it works. :D – Polosson Aug 18 '13 at 14:11
• I've since made an updated blendfile.py, with quite a few changes/optimizations - linked in the answer. – ideasman42 Aug 5 '15 at 23:29