3
$\begingroup$

I'm currently working with drivers in Blender 2.81 and want to use self but it doesn't work.

For example drive the rotation by the location, I'm adding a driver to the rotation, check the Use Self box and write self.location.x

Blender return the message: ERROR Invalid Python expression.

Have I missed something, is it a bug?

edit:

enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ Can you post a picture of driver editor. Recent example doing just this blender.stackexchange.com/a/164893/15543 $\endgroup$ – batFINGER Jan 27 '20 at 14:52
  • 4
    $\begingroup$ also post any error message that may be printed to console re the error in your expression. Make sure there is no leading spaces in expression for example. Look for "Error in Driver: The following Python expression failed:" $\endgroup$ – batFINGER Jan 27 '20 at 15:03
  • 1
    $\begingroup$ blender.stackexchange.com/questions/6173/… $\endgroup$ – batFINGER Feb 1 '20 at 13:52
4
$\begingroup$

I'm working on 2.9. Problem is still here. Allowing auto run python scripts fixed it. enter image description here

$\endgroup$
1
$\begingroup$

Look in the system console.

As an addendum to the accepted answer, to use self in drivers requires enabling auto-run python scripts. However will also get an invalid expression python error, if ... you have an invalid expression.

When you get an error in a driver expression look at the system console.

Where does console output go

Use self and the slow python expression

Turning off allow auto-run python scripts with use self can lead to invalid expression error.. looking at console.

BPY_driver_eval() - restricted access disallows name 'location', enable auto-execution to support

Error in Driver: The following Python expression failed:
'self.location.x'

Will give a big tip that checking enable auto run fixes this... but as demonstrated here

How to use a custom property of an object as input for a driver? an error in the driver expression can also produce an invalid python expression error message.

So for example accidentally on purpose making a typo

enter image description here Will look like this with or without auto run python scripts

self.lodation.x

With python auto run OFF error

    BPY_driver_eval() - restricted access disallows name 'lodation', enable auto-execution to support

Error in Driver: The following Python expression failed:
    'self.lodation.x'

With python auto run ON error

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
AttributeError: 'Object' object has no attribute 'lodation'
$\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.