20
$\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$
4
  • $\begingroup$ You can copy the driver with Right click > Copy Driver, but I'm not sure this is what you want. $\endgroup$
    – gandalf3
    Commented Oct 12, 2013 at 18:48
  • 1
    $\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$ Commented Oct 13, 2013 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
    Commented Oct 14, 2013 at 5:55
  • $\begingroup$ yeah, I have to dig a bit into that. hope i can come up with something :D $\endgroup$ Commented Oct 15, 2013 at 11:42

2 Answers 2

5
$\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$
3
  • $\begingroup$ what about bpy.ops.anim.copy_driver_button()? $\endgroup$
    – gandalf3
    Commented May 15, 2014 at 21:42
  • 1
    $\begingroup$ I am highly suspicious of EVERYTHING from bpy.ops because it relies on editor state, and I routinely run across functions whose input environment is inscrutable. For the copy_driver_button() you have found, how do you specify the "highlighted button" ? $\endgroup$
    – Mutant Bob
    Commented May 16, 2014 at 18:41
  • $\begingroup$ I don't think you're supposed to call bpy.ops.anim.copy_driver_button() from a script, these driver copy\paste operators are in the context-menu for drivable buttons: github.com/dfelinto/blender/blob/master/source/blender/editors/… $\endgroup$
    – R. Navega
    Commented Apr 24, 2018 at 7:09
3
$\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$

You must log in to answer this question.

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