4
$\begingroup$

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
$\endgroup$
5
$\begingroup$

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)

$\endgroup$
  • $\begingroup$ Ah, thanks. Is it a mistake in the docs then that the keyword is included? $\endgroup$ – gandalf3 Dec 28 '14 at 10:02
  • 1
    $\begingroup$ 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. $\endgroup$ – pink vertex Dec 28 '14 at 10:19
  • $\begingroup$ @pinkvertex Thanks, your comment explains why the BGE docs are like that. $\endgroup$ – David Dec 28 '14 at 14:56

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.