Appending all objects from the external blend-file to the scene with Blender Python API

To append all objects from an external blend file to the scene, we can use the BlendDataLibraries mechanism.

Each Blend file along with its main function of working with scenes can also perform the functions of a library – a container filled with meshes, materials, brushes, and other objects that can be loaded into our current working scene.

To access the contents of the blend file and import the necessary objects from it, we can use the “bpy.data.libraries.load” method, specifying the full path to the file containing the required data in its parameters.

When called in this way, the method will return two objects of the “bpy_lib” type. We can use them as lists of “bpy.data” attributes with which we can interact.

For example, the “data_from” attribute names list:

To append all objects from the source file to our scene, we need the “objects” attribute.

We can get the required data by simply assigning data_to = data_from:

After that, cycling through all the objects from “data_to”, we can add them to the scene:

Full code for adding all objects from an external file to the scene:


*.blend file with sample code for my Patreon subscribers.

4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments