0
$\begingroup$

How to get driver value via python?

enter image description here

dr = bpy.data.objects["Cube"].animation_data.drivers[0]
$\endgroup$
2
$\begingroup$

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
0.20000000298023224

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
'modifiers["Bevel"].width'

And hence the value,

>>> C.object.path_resolve(dp)
0.20000000298023224

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)

$\endgroup$

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.