Skip to main content
2 of 3
grammar
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k

Creating a driver on a constraint with python?

I have the following code and want to add a driver to the rest length of the stretch to constraint (bone constraint), but the console says that the property path is invalid. What am I doing wrong?

armature = Name of my armature
str(GrpName)+"_bone" = Name of the armatures bone

BaseLenghtDrv = bpy.data.objects[armature].pose.bones[str(GrpName)+"_bone"].driver_add('pose.bones["'+str(GrpName)+'_bone"].constraints["Stretch To"].rest_length').driver

The code before the driver_add parentheses is definately correct, I tested it with the rotation quaternion of the bone and it worked. But it doesn't work with the bone constraint.