I'm trying to write a script to append an Object or a Collection from a blend file to a new file. Can someone please point what I'm doing wrong?

import bpy

filepath  = "/home/lucas/Desktop/Auto_Eye/02_versions/auto_eye_v03.blend"
directory = "\\Object\\"
filename  = "auto_eye_v03"

bpy.ops.wm.append(filepath=filepath, directory=directory, filename=filename)

This code gives me this error:

Error: '\Object\auto_eye_v03': not a library Traceback (most recent call last): File "/Text", line 7, in File "/home/lucas/Programs/blender-2.80/2.80/scripts/modules/bpy/ops.py", line 201, in call ret = op_call(self.idname_py(), None, kw) RuntimeError: Error: '\Object\auto_eye_v03': not a library

Error: Python script failed, check the message in the system console

And the other method that I've found here on Blender Stack Exchange.

import bpy
scn = bpy.context.scene
filepath = "/home/lucas/Desktop/Auto_Eye/02_versions/auto_eye_v03.blend"

#append object from .blend file
with bpy.data.libraries.load(filepath) as (data_from, data_to):
    data_to.objects = data_from.objects

#link object to current scene
for obj in data_to.objects:
    if obj is not None:

And this code is given me this error.

Traceback (most recent call last): File "/Text.001", line 6, in OSError: load: /home/lucas/Desktop/Auto_Eye/02_versions/auto_eye_v03.blend failed to open blend file

Error: Python script failed, check the message in the system console

  • $\begingroup$ I have a few suspicions. It's saying that "auto_eye_v03" isnt a library, so either you need to define filename as "auto_eye_v03.blend" or you need to tell it which object(s) within that file to append using filename $\endgroup$ – VirtualTurtle Jul 12 '19 at 18:16

With some help on twitter, this code is working now.

import bpy



filepath= .blend file name

directory= directory of your file and the last part is the folder inside the blend file.

filename= Is the object, material, collection or whatever you want to append.

| improve this answer | |

I run this two commands on the Blender Console.

>>> bpy.data.libraries
<bpy_collection[0], BlendDataLibraries>

>>> bpy.data.objects
<bpy_collection[5], BlendDataObjects>

So I didn't have anything on the libraries of the file, but I can't find a way do add then to the libraries.

In the "bpy.data.objects" it lists the objects that I have on the scene, so I need to learn how to append the objects from there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.