2
$\begingroup$

Suppose that obj is a object. If I want to add a driver for its scale X, I can do

d = obj.driver_add("scale", 0).driver

but if obj has the custom property var, the following

d = obj.driver_add("var").driver

gives an error:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct.driver_add(): property "var" not found

How do I add a driver in this case?

$\endgroup$
3
$\begingroup$

The datapath for a custom property is '["propname"]'

obj["prop"] = 34
obj.driver_add('["prop"]')
|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Wow you posted your answer almost at the same time when I posted mine $\endgroup$ – Henricus V. Sep 3 '16 at 5:01
1
$\begingroup$

Solution:

d = obj.driver_add("[\"var\"]").driver
|improve this answer|||||
$\endgroup$

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.