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 definitely correct, I tested it with the rotation quaternion of the bone and it worked. But it doesn't work with the bone constraint.


1 Answer 1


Add the driver to the object, the data path is relative to that:

# We want Object.pose.bones[...].constraints[...].rest_length
# So use an object and the data_path 'pose.bones[...].constraints[...].rest_length'

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

You must log in to answer this question.

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