How to get driver value via python?
dr = bpy.data.objects["Cube"].animation_data.drivers
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
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 >>> 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)