Scan the content of a Blend file?

Is it possible to scan the content of a .blend file? Objects, meshes, materials…
I tried to go with os.path but it seems to not go through a blend file.

path = "D:\\Folder\\my_file.blend\\NodeTree"
for file in os.listdir(path):
    print (file)

What is a .blend file actually? If it’s a zip or a compressed file, maybe I can do what I want with a command that goes through the file?

For the scene it uses the struct DNA format, just in a binary form.

Scanning for “SC” will give the addresses for the scenes.
After “SC” is the scene name “SCScene”, then the data is after the id name.
Same for other objects, “OB” object, “ME” mesh, “AR” armature.

The only real way is to use blender itself, or the original code to create an own blend file reader, because it’s a custom format.

It can be compressed if the user ticket the “Compress” option on save.

You may want to use a python script in Blender to iterate over datablocks and import the ones you want to analyze further:
http://www.blender.org/documentation/blender_python_api_2_72_release/bpy.types.BlendDataLibraries.html#bpy.types.BlendDataLibraries.load

Thanks! this is exactly what I was looking for! :slight_smile:

I have one more question about BlendDataLibraries.
I use it to scan the blend file, it works fine. I can go through objects, meshes, or nodes. But the only information I get is the name. Is there a way to get also the type? if the object for example is a lamp or a mesh object.

no, there are only strings (names). You can loop over all lamp datablocks however, like

with bpy.data.libraries.load(...) as (data_from, data_to):
    data_to.lamps = [...]

It only provides the names per datablock type and lets you assign a list of the datablock names you want to append or link.
Properties of these datablocks can only be examined after you linked or appended them.