# How to add randomness or variability to Action Strip scale

I would like to add variability to an Action Strip's scale, ideally within a range of values I select.

In the wing beat strip below, for example, I would like to scale between something like .3 and .5 with a curve... or noise, or something. This variability is not within the individual actions contained in the AStrip: rather it adjusts the scale of the strip throughout its repeat range.

There isn't a way to set key frames for that value, so as a last resort I wrote a little python script. Copy this into the text editor, and click "run script". Be sure to set the MIN and MAX values, and put the name of the action in the ACTION_NAME variable. The script will automatically choose a new random value every time you change frame. Setting the STEP size will make it wait n number of frames before choosing a new value.

import bpy
from random import random

# Set your min and max values here
MAX = 9
MIN = 3
ACTION_NAME = "DragonflyAction"

# Set step size.  Step size of 1 chooses a new value every frame
STEP = 5

def my_handler(scene):

if scene.frame_current % STEP == 0:
obj = bpy.context.selected_objects[0]
obj.animation_data.nla_tracks["NlaTrack"].strips[ACTION_NAME].scale = (random() * (MAX - MIN)) + MIN

bpy.app.handlers.frame_change_post.append(my_handler)


Here's a screenshot:

While blender doesn't make it easy to add a keyframe or driver to the NLA strip's scale, it is posible to create a driver by typing one directly into the value. You can type a simple driver to create it and then edit the driver once it has been created.

With most editable values in blender we can press I to insert keyframes, we can also type a driver expression straight into the value if we precede it with a # as in entering #frame will create a driver that uses the current frame for the value. For a random value you can enter #noise.random()*12+10 to get a random value between 10 and 22.

You can manually add a keyframe (or driver) using python -

strip = obj.animation_data.nla_tracks['NlaTrack'].strips['DragonflyAction']
strip.scale = 0.35
strip.keyframe_insert('scale', frame=1)


Having said that - a better option would be to add noise to the initial animation and not to the NLA strip settings. In the graph editor you can add a noise modifier to each animated value.

• I didn't realize you could add drivers just by typing in the value. That's pretty cool. Dec 24 '16 at 5:28
• This is great.... and noise within a strip is cool, but not what I need here: The goal is to have repeating actions contained within the strip to repeat at a varying scale -- so a four-beat wing pattern repeating in 10 frames, then 15, then 9... But the cue on creating drivers is great! Dec 24 '16 at 17:25