3
$\begingroup$

I'd like to append all objects from a specific blend file. Some objects in the blend file have drivers attached. For example z-coordinate of the Cube is equal to z-coordinate of the Empty. I used the following simple code for appending.

import bpy

with bpy.data.libraries.load("path/to/test.blend") as (data_from, data_to):
    data_to.objects = data_from.objects

for obj in data_to.objects:
    bpy.context.scene.objects.link(obj)

However, drivers don't work after execution of the above code. They start to work if I go to the driver settings and press "Update Dependecies" button.

What is the trick to make drivers work?

Here is the blend file I'm trying to append:

$\endgroup$
4
  • $\begingroup$ Well, aside from me having to change context.scene to bpy.context.scene and changing self.filepath to "/var/tmp/untitled.blend", I had no difficulty appending an object with a scripted driver using your script. The fact that you are using self.filepath is very odd (If I wanted a copy of something from the current .blend I'd just duplicate it). You may have to upload your .blend, or at least clean up your code example to rule out the possibility that you are confusing blender. $\endgroup$
    – Mutant Bob
    Commented Jul 21, 2015 at 21:15
  • $\begingroup$ @MutantBob The code snippet was used inside an operator, that is why the code had self.filepath and context instead of bpy.context.scene. I'll update the code, so it works without an operator. $\endgroup$
    – vvoovv
    Commented Jul 21, 2015 at 21:48
  • $\begingroup$ I added a blend file $\endgroup$
    – vvoovv
    Commented Jul 21, 2015 at 22:01
  • $\begingroup$ After testing with the .blend you provided, I'm inclined to call this a straight-up bug. The question is still totally valid because you need a workaround until the coders have time to fix the bug. $\endgroup$
    – Mutant Bob
    Commented Jul 22, 2015 at 15:22

1 Answer 1

3
$\begingroup$

The following code does the trick:

import bpy

# prepare files list for bpy.ops.wm.append(..)
files = []
with bpy.data.libraries.load("path/to/test.blend") as (data_from, data_to):
    for name in data_from.objects:
        files.append({'name': name})

bpy.ops.wm.append(directory="path/to/test.blend"+"/Object/", files=files)
$\endgroup$
2
  • 1
    $\begingroup$ It depresses me that the solution is to use bpy.ops. I hope somebody can come up with a better answer. $\endgroup$
    – Mutant Bob
    Commented Jul 21, 2015 at 21:07
  • 1
    $\begingroup$ @MutantBob I have the same feeling and the same hope :) $\endgroup$
    – vvoovv
    Commented Jul 21, 2015 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .