How to get driver value via python?

enter image description here

dr = bpy.data.objects["Cube"].animation_data.drivers[0]

Look at the value of the driven property.

In the example given in question, the bevel modifier width of one cube is being driven by that of another. Have set up similar, the driver value being displayed via UI is 0.2

Given the object of interest has context, retrieve this value by simply

>>> bm = C.object.modifiers['Bevel']
>>> bm.width

Or from the driver, similarly to above a quick visual check confirms the driver is the zeroth

>>> for i, fc in enumerate(C.object.animation_data.drivers):
...     i, fc.data_path
(0, 'modifiers["Bevel"].width')

>>> driver_fcurve = C.object.animation_data.drivers[0]
>>> dp = driver_fcurve.data_path
>>> dp

And hence the value,

>>> C.object.path_resolve(dp)

If the value resolves to an iterable will require using the array_index of the driver [Look for link.]

Consider investigating custom properties as input data to drive from. For set up like above all drivers will break if the driver variable target object with the modifier is removed.

A custom property on the scene can be used as a global and on the object as a local (the use_self option is handy for this)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.