16
$\begingroup$

I want to copy one driver to all selected objects at once, but the "copy to selected" function copies solely the current value of driver, and not the driver itself.

Is there a possibility to copy also the driver to all selected objects?

$\endgroup$
  • $\begingroup$ You can copy the driver with Right click > Copy Driver, but I'm not sure this is what you want. $\endgroup$ – gandalf3 Oct 12 '13 at 18:48
  • $\begingroup$ My issue is more about how to paste the driver to all selected objects at once. just like Right click > Copy to Selected, but it copies only the current value of the selected driver. $\endgroup$ – blenderuser Oct 13 '13 at 11:53
  • 1
    $\begingroup$ I'm not completely sure how to implement this, but you might be able to make some sort of "copy drivers to selected" operator, or use python to paste drivers for objects automatically $\endgroup$ – gandalf3 Oct 14 '13 at 5:55
  • $\begingroup$ yeah, I have to dig a bit into that. hope i can come up with something :D $\endgroup$ – blenderuser Oct 15 '13 at 11:42
4
$\begingroup$

I'm going to say there is not yet a quick way to do it.

The closest I can come to accomplishing your mission is this python script (which you can put in a Text Editor panel and use the Run Script button on the right of the toolbar, which means you might need to widen the panel)

Select all your objects, and select the source object last (so it is the active object), then click Run Script.

import bpy
import sys

def copyDriver(src, tgt):
    if tgt.animation_data is None:
        tgt.animation_data_create()
    print(tgt)
    if False:# or isArrayPath(src.data_path):
        d2 = tgt.driver_add(src.data_path, src.array_index)
    else:
        d2 = tgt.driver_add(src.data_path)

    d2.driver.expression = src.driver.expression
    for v1 in src.driver.variables:
        copyVariable(v1, d2.driver)

def copyVariable(src, tgt):
    v2 = tgt.variables.new()
    v2.type = src.type
    v2.name = src.name
    try:
        v2.targets[0].data_path = src.targets[0].data_path
        v2.targets[0].id_type = src.targets[0].id_type
        v2.targets[0].id = src.targets[0].id
    except:
        print("dang, %s %s"%(src.targets[0].id, sys.exc_info()[0]) )

def isArrayPath(path):
    return path == 'location' or path == "dimensions" or path == "rotation"

print ( isArrayPath("location") )
print ( isArrayPath("text_box[0].x") )


scn = bpy.context.scene

src = bpy.context.active_object

for obj in scn.objects:
    if (obj==src):
        continue
    if obj.select:
        print("object")
        if not src.animation_data is None:
            for dr in src.animation_data.drivers:
                copyDriver(dr, obj)
        print("data")
        if not src.data.animation_data is None:
            for dr in src.data.animation_data.drivers:
                copyDriver(dr, obj.data)

I have tested this only partially. I did not even attempt to copy modifiers. I'm sure there are some other driver doodads I'm not properly copying.

Anyway, I expect if someone can find a reliable API function to replace my copyDriver() kludge, your life will get a lot easier.

In the mean time, feel free to point out shortcomings and I'll see if I can kludge a way around it.

$\endgroup$
0
$\begingroup$

The super simple solution is in the menu Object -> Make Links -> Animation data. This also copies all animation but for me it proved to be invaluable since manually copy-pasting drives can be tedious when there are dozens of those objects. Like with any data copying in Blender, it copies from active object to all selected objects.

$\endgroup$

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.