Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Pause & continue to an expression

  • Pause & continue to an expression

    Posted by Oguz Akalin on August 13, 2020 at 2:37 pm

    Hi,

    My question already might have been sorted out somewhere but I couldn’t find a proper answer for 2 hours. So please help:)

    I need to pause&continue an expression by using a checkbox. I have loopOut(“offset”) on the rotation property with just 2 keyframes. So the rotation value is 0 in the first frame, 3 at fr150, 3.80 at fr190, and so on. On a given time by keyframing the checkbox, say at 250th frame, I’d like the expression to read and keep that value, which is 5, until the next checkbox keyframe. And from the next keyframe, I want it to start again adding the value on top of 5, the value of the previous checkbox keyframe at the 250th frame.

    Any ideas, please?
    Thank you

    Oguz Akalin replied 6 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    August 13, 2020 at 10:12 pm

    Hi Oguz,

    It was a pretty tough one, too bad that loopOut() doesn’t take a third parametr for time, so I had to rewrite code to mimic what loopOut(“offset”) does.
    This is the final expression for rotation:


    ch=effect("Freeze")("Checkbox"); // point to your checkbox
    n = ch.numKeys;

    // start-stop time variable adapted from Dan's Speed control integrator
    if (n<2) {
    t=time * !ch.value;
    } else {
    t=ch.key(2).time * !ch.key(1).value;
    for(i=2; i time) break;
    t+=(ch.key(i+1).time - ch.key(i).time) * !ch.key(i).value;
    }
    t+=!ch.value*(time-ch.key(i).time);
    }

    // fake loopOut(offset):
    if (numKeys>1 && t>key(numKeys).time) {
    k1 = key(1).time;
    knk = key(numKeys).time;
    delta = key(numKeys).value - key(1).value;

    // have to do stupid conversion to framenumbers because of % vs / rounding errors }:-(
    loopTime = timeToFrames(k1) + (timeToFrames(t-k1) % timeToFrames(knk-k1));
    loops = Math.floor(timeToFrames(t-k1) / timeToFrames(knk-k1));
    // now convert back
    l = valueAtTime(framesToTime(loopTime)) + (loops*delta);
    } else {
    l = valueAtTime(t);
    }

    Right now the code works that when the checkbox is ON -> time stops. That’s why I named it freeze.
    To invert the behavior (time freezes when it’s OFF) change every !ch.value into ch.value

  • Oguz Akalin

    August 13, 2020 at 10:58 pm

    Hey Filip, frankly I wasn’t expecting to cause that much pain, so thank you very much!
    But looks like there might be a syntax issue (unexpected identifier) here:

    Thank you

    } else {
    t=ch.key(2).time * !ch.key(1).value;
    for(i = 2; i time) break;
    t+=(ch.key(i+1).time - ch.key(i).time) * !ch.key(i).value;
    }

  • Filip Vandueren

    August 13, 2020 at 11:16 pm

    Yes, sorry, problems with < and > characters.


    ch=effect("Freeze")("Checkbox"); // point to your checkbox
    n = ch.numKeys;

    // start-stop time variable adapted from Dan's Speed control integrator
    if (n < 2) {
    t=time * !ch.value;
    } else {
    t=ch.key(2).time * !ch.key(1).value;
    for(i=2; i < n ; i++) {
    if (ch.key(i).time > time) break;
    t+=(ch.key(i+1).time - ch.key(i).time) * !ch.key(i).value;
    }
    t+=!ch.value*(time-ch.key(i).time);
    }

    // fake loopOut(offset):
    if (numKeys>1 && t>key(numKeys).time) {
    k1 = key(1).time;
    knk = key(numKeys).time;
    delta = key(numKeys).value - key(1).value;

    // have to do stupid conversion to framenumbers because of % vs / rounding errors }:-(
    loopTime = timeToFrames(k1) + (timeToFrames(t-k1) % timeToFrames(knk-k1));
    loops = Math.floor(timeToFrames(t-k1) / timeToFrames(knk-k1));
    // now convert back
    l = valueAtTime(framesToTime(loopTime)) + (loops*delta);
    } else {
    l = valueAtTime(t);
    }

  • Oguz Akalin

    August 14, 2020 at 1:59 pm

    Wow, it worked like magic:)
    Thank you so much Filip!

    Cheers

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