The bpy.ops.ui.copy_as_driver_button()
and bpy.ops.anim.paste_driver_button()
functions are operators in Blender's Python API, which means they are designed to be called from the Blender interface. As far as I know, it's not possible to call these functions directly from a Python script.
Instead of using these functions, you can achieve the same result by accessing the data that the operator manipulates directly. For example, you could use the driver_add()
method of a property to add a new driver. In the following example, I add a driver to the default cube's X and Y scale properties, which are indices 0 and 1, respectively:
import bpy
obj = bpy.data.objects["Cube"]
def add_driver(ob, idx):
fc = ob.driver_add('scale', idx)
d = fc.driver
d.type = "AVERAGE"
v = d.variables.new()
t = v.targets[0]
t.id_type = 'OBJECT'
t.id = ob
t.data_path = "scale[2]"
add_driver(obj, 0)
add_driver(obj, 1)
Now you can adjust the Z scale and have X and Y scales update to the same values.
See the thread How can I add and configure a Driver through a Script for more information about scripting drivers.