import bpy
import sys
def copyTarget(src, tgt):
tgt.data_path = src.data_path
tgt.id = src.id
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:
copyTarget(src.targets[0], v2.targets[0])
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)
|
Blender python API quick-start
Syntax highlighting by Pygments.