6

I want to add a driver to the Z location of an object via python.
After reading the docs and this question, I would guess something like this:

bpy.context.object.driver_add("location", index=2)

However when run in the python console it says

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: driver_add() takes no keyword arguments
gandalf3
  • 157,169
  • 58
  • 601
  • 1,133

1 Answers1

8

The error message gives a hint:

TypeError: driver_add() takes no keyword arguments

So pass the index as positional argument:

bpy.context.object.driver_add("location", 2)

pink vertex
  • 9,896
  • 1
  • 25
  • 44
  • Ah, thanks. Is it a mistake in the docs then that the keyword is included? – gandalf3 Dec 28 '14 at 10:02
  • 2
    It is confusing. The python api documentation uses templates provided by sphinx. This notation indicates that the second parameter is optional and also specifies its default value. An annotation that no keyword arguments are allowed should be added. – pink vertex Dec 28 '14 at 10:19
  • @pinkvertex Thanks, your comment explains why the BGE docs are like that. – David Dec 28 '14 at 14:56