6

how can i add a driver for a shapekey via python?

shape_keys.animation_data.driver_button_add(True)

or

obj=bpy.context.active_object
obj.driver_add('key_blocks["Eye_left"].value')

The Problem is that it can't find the shape key and shape keys are getting their driver with a different method; so I'm a bit confused how it can be added by python correctly. Sorry I'm new to Python. Thanks for your help!

tst
  • 63
  • 3

1 Answers1

8
import bpy

obj = bpy.context.active_object
driver = obj.data.shape_keys.key_blocks['Key 1'].driver_add("value")
pink vertex
  • 9,896
  • 1
  • 25
  • 44
  • 2
    Docs say driver_add() returns a FCurve object, so you don't have the driver yet: driver = obj.data.shape_keys.key_blocks['Key 1'].driver_add("value").driver (https://docs.blender.org/api/2.79/bpy.types.bpy_struct.html#bpy.types.bpy_struct.driver_add) – R. Navega Mar 14 '18 at 08:18