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 <module> 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: scn.objects.link(obj)
And this code is given me this error.
Traceback (most recent call last): File "/Text.001", line 6, in <module> 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
I run this two commands on the Blender Console.
>>> bpy.data.libraries <bpy_collection, BlendDataLibraries> >>> bpy.data.objects <bpy_collection, 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.