3
$\begingroup$

I’d like to write a script that will tell me which drivers in a scene have problems. For example, the driver that I’ve highlighted in yellow has problems:

I want to return a list of every driver that has problems, rather than having to look at each driver in a scene individually and determine if it is valid.

Here’s what I have so far:

 import bpy
 for obj in bpy.context.scene.objects: 
     if obj.animation_data:
         if obj.animation_data.drivers:
             for d in obj.animation_data.drivers:
                 if d.driver.is_valid == False:
                     # Now what??

The issue is trying to figure out the name of the property that has the driver. I’ve looked in the API documentation and it’s not immediately obvious how to get that.

In the case of the screenshot above, I want to get (or create) the string value "Y Euler Rotation (forearm.IK.L)".

How do I do that?

$\endgroup$

1 Answer 1

3
$\begingroup$

Just like keyframes look at data_path and array_index

data_path is the path from the owner of the driver, array index if it is an array type, eg 0, 1, 2 for x, y, z locations.

Example Y Euler rotation of pose bone "shin.L", from the context object in python console.

>>> for d in C.object.animation_data.drivers:
...     d.data_path, d.array_index
...     
('pose.bones["shin.L"].rotation_euler', 1)


>>> C.object.pose.bones['shin.L'].rotation_euler[1]
2.0

>>> C.object.pose.bones['shin.L'].rotation_euler.y
2.0

Note for booleans unnecessary to test equality to True/False ,

if not d.driver.is_valid: 
$\endgroup$
1
  • 1
    $\begingroup$ Perfect! I got what I needed out of that. Thanks, batFINGER! $\endgroup$
    – Andr
    Feb 16, 2020 at 15:38

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.