3
$\begingroup$

I can access the shapekeys of an object like:

bpy.data.objects['mesh'].data.shape_keys.key_blocks

And I can get the "shapekeys package" of the object with:

bpy.data.objects['mesh'].data.shape_keys.name

I can access the drivers from that "shapekeys package":

bpy.data.shape_keys['Key.002'].animation_data.drivers.items()


I need to check scripted expressions and variables from drivers. The access could be this way:

bpy.data.shape_keys[bpy.data.objects['mesh'].data.shape_keys.name].animation_data.drivers.items()

Would be this the best way (more short) to access this info?

$\endgroup$

1 Answer 1

5
$\begingroup$

All shape keys are stored in bpy.data.shape_keys and can be applied to multiple objects. Each object possesses an attribute pointing to the shape key if it is using any. Thus

shape_key = bpy.data.objects['yourObject'].data.shape_keys

will give you access to it directly.

bpy.data.shape_keys is a bpy_prop_collection which allows access to its elements by name or index.

So if you know the index or the name of a shape key you will probably want to access it from bpy.data.shape_keys.

If you don't know which shape key is used by an object you will retrieve it from obj.data.shape_keys.

Expression & Variables:

# Access by index only
driver = bpy.data.shape_keys['Key.002'].animation_data.drivers[index]
driver.driver.expression
driver.driver.variables
$\endgroup$
4
  • $\begingroup$ Then access to drivers only can be made by index, right? $\endgroup$
    – gabrign
    Feb 2, 2014 at 15:01
  • 1
    $\begingroup$ Yes. Pass an integer. The keys() method which is supposed to return the available string keys of the elements in the collection always returns an empty list [] for drivers. $\endgroup$ Feb 2, 2014 at 17:13
  • $\begingroup$ It's the same for Object.animation_data.action.fcurves.keys(), and it's not even a bug. There's simply no name, only data_path and array_index, which sort of identifies a Driver/FCurve. But it's possible to have both properties set to the same values, although only the one with the highest index number (bottom-most channel in F-Curve Editor) is apparantly evaluated (even for delta-transforms). Hence, you need to either use the index, or loop over all .fcurves or .drivers, check the data_path and array_index values and pick the one you are after. $\endgroup$
    – CodeManX
    Feb 3, 2014 at 11:18
  • $\begingroup$ I'm accesing now to drivers name via "data_path". Well, thanks to everyone about this! $\endgroup$
    – gabrign
    Feb 3, 2014 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .