Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Make a Layer Grow at each Marker

  • Make a Layer Grow at each Marker

    Posted by Surya Buchwald on January 23, 2012 at 5:06 am

    I’d like to make a layer grow at each marker. Thanks to other posts in this forum, I’ve come as far as the attached expression. However, the layer resets to the default scale at each marker instead of building on the current scale. I thought that grabbing the scale using valueAtTime() and plugging in the time of the marker would provide the solution, but it’s not happening. Any ideas?

    var growSpeed = 10;
    var growPeriod = 0.1;

    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time) {
    n--;
    }

    if (n > 0) {
    t1 = marker.key(n).time;
    t2 = t1 + growPeriod;
    startScale = scale.valueAtTime(t1)[0];
    temp = linear(time, t1, t2, startScale, (startScale + growSpeed));
    [temp,temp];
    } else {
    // do nothing
    value;
    }
    }

    Dan Ebberts replied 14 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 23, 2012 at 5:49 pm

    An expression has no way to access results from its own calculations at previous frames. There are various ways to work around this limitation. In your case, I think you just need to change the line that defines startScale to this:

    startScale = value[0] + (n-1)*growSpeed;

    That will accumulate the result of previous markers. I haven’t tested it, but it should be close.

    Dan

  • Surya Buchwald

    January 23, 2012 at 6:26 pm

    Thank you! That did indeed solve the issue. And I understand better what is going on. I was hoping that valueAtTime would sample the expression-result value at the marker time, but based on your example, it will always sample the keyframed value, which in this case is just the value. So instead we take the current value and add to it the known grow amount from all the previous markers. Great!

    Theoretical addendum: if we were growing by a random amount instead of a fixed amount, would there still be a way to track this?

  • Dan Ebberts

    January 23, 2012 at 6:29 pm

    In that case, you’d have to use a loop to recreate the random values for each previous maker and add them up.

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy