enter image description here

i set up cube rotation and movement by object near by cube,but i also want to set up its z location so it cannot penetrate through plane every time it move forward and backward,there is some problem in expression i use in driver. enter image description here

  • 3
    $\begingroup$ You've got an extra closing parenthesis at the end of the line (or a missing opening one somewhere) $\endgroup$
    – thibsert
    Mar 10, 2019 at 12:25

1 Answer 1


Use a python console

enter image description here

Recommend using a python console or a text editor to crunch in your expressions when they get too complex. See image in the way it has shown the error message. Most syntax aware text editors have some way to highlight matching brackets, including blender.

Define any variables in your expression first with dummy values

>>> x = 1

Conveniently if using the python console, the math methods are already imported, .

>>> locals().keys()
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__builtins__', 'bpy', 'C', 'D', 'help', 'Vector', 'Matrix', 'Euler', 'Quaternion', 'Color', 'geometry', 'interpolate', 'noise', 'bvhtree', 'kdtree', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log1p', 'log10', 'log2', 'modf', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'pi', 'e', 'tau', 'inf', 'nan', 'M', 's', 't', 'x', 'bmesh'])

just as most are known to the driver namespace (can be used in driver expressions)

>>> bpy.app.driver_namespace.keys()
dict_keys(['__builtins__', '__name__', '__doc__', '__package__', '__loader__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log1p', 'log10', 'log2', 'modf', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'pi', 'e', 'tau', 'inf', 'nan', 'bpy', 'noise'])

In the case you crunch in hit enter and the next line presents you with ... it most likely means you are missing a brace.

>>> sqrt(2) * (x - round(x, 0)) if (x % 2) < 1 else sqrt(2) * (x % 2
... )

Test with different input values. The history (up and down arrows) saves retyping everything

>>> x = 0.33
>>> sqrt(2) * (x - round(x, 0)) if (x % 2) < 1 else sqrt(2) * (x % 2)

And when you are happy with it, select it with the mouse copy CtrlC and then paste CtrlV into the driver expression

See also defining a driver method and adding to namespace [Find Link]

  • $\begingroup$ thanx it is working now correctly. $\endgroup$ Mar 10, 2019 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .