FORUMS: list search recent posts

# Expression on and off with several layer markers

FAQ   •   VIEW ALL
 Expression on and off with several layer markers on Mar 25, 2011 at 8:32:51 pm

I'm sure this isn't too complicated and I'm somewhat new to expressions so I need a little help. Done plenty of searching and nothing out there I could find.

Basically I would like to use layer markers(not an expression controller that I need to keyframe) in order to turn a wiggle expression on and off for position. I'm sure the on and off will work on any expression but I've only found expressions that let me turn it on and off once. I'd like to be able to add markers and then resume the wiggle.

I'm guessing I need to do some kind of odd/even detection of my marker but I'm having trouble understanding the basics behind how the layer marker expressions and code are processed. Here's something I found and have tried to modify with no luck. Pretty sure it was from the man Dan.

Hoping I'm not the only one that would find this useful and easier than keyframing.

```n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time){ n--; } } if (n > 0){ wiggle(5,40) }else{ value }```

 Re: Expression on and off with several layer markerson Mar 25, 2011 at 10:11:36 pm

The simplest way would be like this:

``` n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time) n--; } if (n%2) wiggle(5,40) else value ```

That method jumps abruptly to and from the wiggle value so you might be happier with this:

``` easeTime = .1; n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time) n--; } if (n > 0){ t = time - marker.key(n).time; if (n%2){ ease(t,0,easeTime,value,wiggle(5,40)) }else{ ease(t,0,easeTime,wiggle(5,40),value) } }else{ value } ```

There's a more complicated way that picks the wiggle up where it left off, but hopefully one of these will do the trick.

Dan

 Re: Expression on and off with several layer markerson Mar 26, 2011 at 4:41:52 am

I can think of situations where I might want to ease the wiggle in and out and also some where it would be nice to be abrupt.

This is great. Thanks a ton Dan. I do understand that you're checking for odd/even with the modulus(%2), just wish I could grasp how the entire expression processes it.

They should make a translator for expressions. I guess your site kind of does that already. :)

 Re: Expression on and off with several layer markerson Mar 26, 2011 at 4:55:12 am

Here's the one that resumes the wiggle from the previous hold point:

``` n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time) n--; } t = 0; if (n > 1){ for ( i = 2; i <= n; i += 2){ t += marker.key(n).time - marker.key(n-1).time; } } if (n%2) t += time - marker.key(n).time wiggle(5,40,1,.5,t) ```

Dan

 Re: Expression on and off with several layer markerson Mar 28, 2011 at 3:24:50 pm

works very nice, thanks Dan.

I wish I could understand all of that, but just one question for now...

What's the "i" variable doing in that line?

 Re: Expression on and off with several layer markerson Mar 28, 2011 at 4:20:41 pm

Yikes. Good question. That's not correct - it should be like this:

``` n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time) n--; } t = 0; if (n > 1){ for ( i = 2; i <= n; i += 2){ t += marker.key(i).time - marker.key(i-1).time; } } if (n%2) t += time - marker.key(n).time wiggle(5,40,1,.5,t) ```

Dan