1
$\begingroup$

There are lots of bones and right side bones and left side bones have same constraint. I always copy right side bones constraint parameter as driver and paste them on same parameter of left side bones constraint. I would like to do it using python.

enter image description here

For example there are Bone_R and Bone_L and both have copy location constraint. And I tweaked influence parameter of Bone_R's copy location constraint and I do "Copy As New Driver" on the influence parameter and paste the driver on influence parameter of Bone_L's copy location constraint. Is it possible to automate this task using python? At least "Copy As New Driver" command accesses right side bone's copy location parameter so, I can have bones name and its copy location influence status, then if so I simply change the path (like copy location influence of Bone_R to copy location influence of Bone_L)and paste the driver, but I don't know how.

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Assuming you have only 1 armature named Armature which contains bones named Bone_R and Bone_L, you can use the following script to add a driver to Bone_L's Copy Location Constraint's Influence parameter which is driven by Bone_R's Copy Location Constraint's Influence parameter:

import bpy

armature = bpy.data.objects['Armature']

bone_R = armature.pose.bones['Bone_R']
bone_L = armature.pose.bones['Bone_L']

constraint = next((c for c in bone_L.constraints if c.type == 'COPY_LOCATION'), None)

fc = constraint.driver_add('influence')
d = fc.driver

v = d.variables.new()
v.name = "influence"
target = v.targets[0]
target.id_type = 'OBJECT'
target.id = armature
target.data_path = 'pose.bones["Bone_R"].constraints["Copy Location"].influence'
d.expression = "influence"

If you have multiple armatures with this type of bone configuration, just loop through every armature and execute that same script. For more information on using or scripting drivers see How can I add and configure a Driver through a Script

$\endgroup$
3
  • $\begingroup$ thank you. is it possible to use Blender's "Copy As New Driver" ? I thought it saves something in clipboard and let us paste it on any parameters. $\endgroup$
    – Yokomizo
    Commented Apr 17, 2023 at 21:15
  • $\begingroup$ It's not possible to directly use bpy.ops.ui.copy_as_driver_button() and bpy.ops.anim.paste_driver_button(). Or at least nobody knows I think. blender.stackexchange.com/questions/181797/… $\endgroup$
    – Harry McKenzie
    Commented Apr 18, 2023 at 1:37
  • 1
    $\begingroup$ oh. too bad. bpy.ops.ui.copy_as_driver_button() is really useful so I wanted to use it. I've made a script using your script. it makes a new driver to L side bones referencing R side bone's Copy Location, Copy Rotation, Copy Scale, and Transform constraints. very useful. thank you. $\endgroup$
    – Yokomizo
    Commented Apr 19, 2023 at 1:52

You must log in to answer this question.

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