How to Use Expressions in Blender Drivers

Blender driver expressions allow you to control object properties dynamically using mathematical formulas and Python-based scripting. By linking properties together or utilizing time-based variables, drivers automate complex mechanical movements, rigging behaviors, and parametric animations without manual keyframing.

Step 1: Add a Driver to a Property

  1. Locate the property you want to control (such as Location, Rotation, Scale, or Material values).
  2. Right-click the input field and select Add Driver.
  3. A pop-up menu will appear to configure the driver. To access full controls at any time, right-click the field and choose Edit Driver, or open the Drivers Editor from the animation workspace.

Step 2: Define Variables

Drivers rely on input variables to read data from the scene:

  1. In the driver configuration panel, change the Type to Scripted Expression.
  2. Scroll to the Input Variables section. By default, a variable named var is provided.
  3. Configure var to sample the desired property:
    • Transform Channel: Reads position, rotation, or scale from another object in World Space or Local Space.
    • Single Property: Reads a specific data path (such as a custom property or modifier value).
    • Context Property: Reads values dependent on the active scene or view layer.
  4. Add more variables using the Add Variable button if your expression requires multiple inputs.

Step 3: Write the Expression

In the Expression field, enter your mathematical formula using Python syntax. Blender executes this expression on every frame change to calculate the property value.

Common Expression Examples

  • Direct Proportions:

    var * 2.5

    Multiplies the input variable by 2.5. Useful for gear ratios.

  • Inverting Direction:

    -var

    Reverses the motion of the target property relative to the source.

  • Time and Frame-Based Movement:

    sin(frame * 0.1) * 2

    Uses the global variable frame with the sine function to create a continuous oscillating wave motion between -2 and 2.

  • Combining Multiple Variables:

    (var_a + var_b) / 2

    Averages the values of two distinct variables.

  • Conditional Expressions (Ternary Operator):

    var if var > 0 else 0

    Clamps the output so that negative values return 0.

Supported Functions and Constants

Blender includes built-in access to standard Python mathematical operations and constants without requiring module imports:

  • Constants: pi, True, False
  • Trigonometry: sin(), cos(), tan(), asin(), acos(), atan()
  • Rounding and Utility: abs(), round(), floor(), ceil(), min(), max()
  • Power and Roots: pow(x, y), sqrt()
  • Scene Variables: frame (current frame), time (current time in seconds)

Step 4: Security and Execution

If your expression uses advanced functions or external Python modules, Blender may require you to enable execution:

  1. Go to Edit > Preferences > Save & Load.
  2. Check Auto Run Python Scripts to ensure custom Python expressions evaluate automatically when opening project files.