9
$\begingroup$

It is possible to use the variable #frame in an input field to make the value increment with each frame. It behaves as a Driver.

Example:

Pound sign "frame" input

We can also halve or double the rate using #frame/2 or #frame*2 respectively. So I got to wondering to what extent we can write expressions in input fields. How complex can we get?

Is it also possible to input a sine wave as an expression?

The purpose would be for quickly animating objects that move cyclically:

A pendulum oscillating in a sine wave

$\endgroup$
1
  • 2
    $\begingroup$ That thing is hypnotic. I am getting sleepy, sleepy $\endgroup$
    – batFINGER
    Commented Oct 25, 2015 at 13:38

1 Answer 1

9
$\begingroup$

Sure, why not. The # symbol in the input field tells blender that you are inserting scripted driver with no variables. Everything after # will be put into the driver's expression field.

You can get a list what functions are build-in by typing bpy.app.driver_namespace[' into the console and hitting CtrlSpace.

You can totally input #cos(frame*pi/20) to match the curve you provided in the question.

$\endgroup$
3
  • 2
    $\begingroup$ You can add your own item to the driver namespace bpy.app.driver_namespace["foo"] = bar, foo is how you reference it in a driver expression. foo / 2 foo(frame) sin(foo) etc. The driver expression must have a return value of type float or int $\endgroup$
    – batFINGER
    Commented Oct 25, 2015 at 13:37
  • $\begingroup$ Excellent! This is exactly what I was looking for. Thank you! $\endgroup$
    – Mentalist
    Commented Oct 25, 2015 at 13:50
  • 1
    $\begingroup$ @Mentalist Another handy tip is passing the locals() dictionary via a driver expression eg foo(locals()) locals() is a key, value dictionary, eg if driver has one variable var with a value of 1.4 the locals dictionary will be {"var":1.4} $\endgroup$
    – batFINGER
    Commented Oct 26, 2015 at 18:03

You must log in to answer this question.

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