2
$\begingroup$

I'm trying to get the name of the property that's been affected by a driver for a certain object, what I did so far:

for d in bpy.context.object.animation_data.drivers:
    print(d.driver.id_data.name)

However, that's returning the name of the object, not the driven property.
My question is, let's say there's a drive controlling the Z Scale, how do I get that information "Z Scale" or a similar equivalent, in scripting?

$\endgroup$
  • $\begingroup$ Related blender.stackexchange.com/questions/111662/… $\endgroup$ – batFINGER Oct 26 at 11:45
  • $\begingroup$ Thank you @batFINGER very helpful, as always $\endgroup$ – Georges Oct 26 at 11:47
  • 1
    $\begingroup$ Cheers. Initially closed as a dupe, ... changed mind after looking at answer script which will do nought if there are no variables, which is often the case with use_self or when using frame or other vars known to namespace. Closing is no big deal tho, more in re to linking alike questions. $\endgroup$ – batFINGER Oct 26 at 12:01
  • $\begingroup$ Totally agree, I believe answers to both questions are helpful $\endgroup$ – Georges Oct 26 at 12:08
4
$\begingroup$

Use f_curve.data_pathand f_curve.array_index to get the property index in case of vectorized properties (like location, scale, etc.)

import bpy

if bpy.context.active_object and bpy.context.active_object.animation_data:
    for d in bpy.context.active_object.animation_data.drivers:
        print(bpy.context.active_object)
        print(f"Driven property : {d.data_path}")
        print(f"Property index : {d.array_index}")

Example :

enter image description here

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Great answer, thank you $\endgroup$ – Georges Oct 26 at 11:40

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.