Inspecting other .blend files via python

Hello all,

Does anyone know of a way to get information from another .blend file using python? For example, if you currently have the file SomeObjects.blend open, and you want to import a scene or object from SupplementaryObjects.blend, is there some way you can read out the list of scenes / objects in SupplementaryObjects.blend while you still have SomeObjects.blend open?

(Obviously you can do this with File->Append; I’m looking for a way to create a python list of all the scenes that could possibly be imported from a .blend file).

Thanks for your help!

http://blenderartists.org/forum/archive/index.php/t-176343.html
looks promising,

20-Feb-10, 19:56

bpy.ops.wm.link_append(path="//Test.blend/Object/MyItem",filename="MyItem",directory="/Users/MyComputer/Desktop/3D/Test.blend/Object/")

Author = Pipeline
My problem was that I neglected to add the directory string. For some reason, the official documentation (http://www.blender.org/documentation/250PythonDoc/bpy.ops.wm.html?highlight=link_append#bpy.ops.wm.l ink_append) says it’s all ‘optional’, so… Anyway, it works like this :slight_smile:

read the entire thread, it’s quite interesting. Link_append doesn’t seem to implement the ability to list the items in the blend at runtime… The workaround seems more involved that it needs to be.

this can help (2.57 ok, not 2.56a):

with bpy.data.libraries.load(blend) as (src, dest):

https://github.com/pierriko/morse/blob/master/src/morse/builder/generator.py
http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.BlendDataLibraries.html

Thanks pierriko, the bpy.data.libraries.load() function is exactly what I was looking for!