How to get driver for z location by name (without looping)

2018-01-13 00:37:24

I wish to be able to reference the driver for Location Z by name. Whenever I try using somethings like

object.animation_data.drivers[object.location.z]

or

object.animation_data.drivers[object.location[2]]

I get

TypeError:bpy_prop_collection[key]: invalid key, must be a string or an int, not Float

Any object I will call this function on will have a driver for Z location. Instead of iterating through the collection I was hoping I can call it by name (like properties).

I was able to find in the API documentation that there is a built in function for this collection.

Calling

object.animation_data.drivers.find('location',2)

did the trick.

  • I was able to find in the API documentation that there is a built in function for this collection.

    Calling

    object.animation_data.drivers.find('location',2)

    did the trick.

    2018-01-13 01:57:11