Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger Time Remap with a Checkbox Control

  • Trigger Time Remap with a Checkbox Control

    Posted by Paulius v Ruksa on July 2, 2021 at 11:00 am

    Hello! I was wondering if anyone could help me out.

    I am working on a UI motion for an app. I am dealing with a lot of different components that live in a lot of different precomps. The app is still being designed so it is important for me to be able to

    make changes fairly quickly as I go along hence I have expression controls that reference different precomps for things like scrolling, swiping, etc.

    There is one thing that I can’t quite figure out. For example, I have an animated icon that I want to set up in a way that I could trigger from a different comp using a checkbox control.

    My animation is 0-40 frames and I would like to reference time remap for that comp. So if the checkbox is unchecked it needs to be on frame 0, when turned on it needs to animate from 0 to 40 and hold.

    My knowledge in AE expressions is very basic so at the moment I have this (which is set up on time remap on the icon precomp):

    if (comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”)== false) {0} else {40}

    This of course doesn’t work because when I check the box it just jumps to frame 40, what I need it to do is to animate from 0 to 40 and stay on 40.

    I have found some other discussions here with a very similar question, but I can’t seem to be able to apply those expressions to my comp.

    Any help would be really appreciated.

    Thanks!

    Paulius v Ruksa replied 4 years, 10 months ago 4 Members · 6 Replies
  • 6 Replies
  • Andrei Popa

    July 2, 2021 at 3:00 pm

    Time in expressions is in seconds. I think it jumps to 40 second, not frame. However, that is not important. Try this and tell me if it works:

    if (comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”)== false) {
    0
    } else {
    endT = framesToTime(40);
    linear(time,0,endT,0,endT);
    }

    if you want the animation to start at the inPoint of the composition, use this:

    if (comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”)== false) {
    0
    } else {
    endT = framesToTime(40);
    linear(time,inPoint+0,inPoint+endT,0,endT);
    }
  • Paulius v Ruksa

    July 5, 2021 at 7:44 am

    Hi Andrei, thank you for your reply!

    The second expression is definitely closer, but it still doesn’t behave completely right, if it’s unchecked it’s at frame 0 if it is it animates from whatever frame I am on at that moment which doesn’t work as I always need it to animate from frame 0 and hold on 40.

    I tried to change some of the numbers and experiment with it. For example if I change the bold number 0 to say 40 it does what I need it to do, but it does it really slowly. as you mentioned that time in expressions is in seconds, I tried to use 2, but that didn’t work either.

    Any ideas what could be missing?

    if (comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”)== false) {
    0
    } else {
    endT = framesToTime(40);
    linear(time,inPoint+0,inPoint+endT,0,endT);
    }

    Thanks!

  • Robert Müller

    July 5, 2021 at 9:16 am

    Hi, so you want to let the time remapping happen when you click (set a keyframe to change the value) the checkbox right? Then you might need to use a for loop like this:

    Im not really good at those loop things so this is not a perfect solution – like when you switch from off to on multiple times or you have 0 keyframes on your checkbox – but maybe someone else can help as well? 🙂

    c=comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”));
    for(i=1;i<=c.numKeys;i++){
    if (c.key(i).value== false) {
    0
    } else {
    endT = framesToTime(40);
    linear(time,c.key(i).time,c.key(i).time+endT,0,endT);
    };
    }
  • Paulius v Ruksa

    July 5, 2021 at 9:50 am

    Thanks a lot for your help, Robert!

    I still couldn’t get it to work, but I had another look at older threads and found this one:

    https://creativecow.net/forums/thread/trigger-a-animation-using-a-checkbox/

    One of Dan’s expressions work perfectly for my case. I have tried it before but must have made a mistake, now I applied it to my comp again and it works as it should. It’s this one here by Dan Ebberts (applied to my comp):

    <pre class=””>

    n = 0;

    p = comp(“2.1a. Creator”).layer(“ICON_CTRL”).effect(“ICON_CTRL”)(“Checkbox”);

    if (p.numKeys > 0){

    n = p.nearestKey(time).index;

    if (p.key(n).time > time) n–;

    }

    if (n > 0 && p.key(n).value)

    time – p.key(n).time

    else

    0

    Having said that, I have another question someone might be able to help me figure out?

    In my main comp, I have a few components with videos. As I’m animating a scroll, the videos need to start playing. So In the Precomp I have a still layer and the video layer. I’m using a simple expression like this applied to Opacity:

    if (comp("2.1a. Creator").layer("VIDEO_CTRL").effect("VIDEO_3")("Checkbox")== true) {100} else {0}

    I’m simply showing the video on top of the still while the checkbox is on. The client however wants me to play sound with the video so I added a Slider Control to Levels and using the same checkbox to control the volume like this:

    if (effect("VIDEO_3")("Checkbox")== true) {0} else {-100}

    I was wondering if there’s any way to fade in the audio say in 20 or so frames rather than cut to it? So I want to use the same keyframe to start previewing the video as well as fade in its audio.

    Thanks!

    Trigger a animation using a checkbox

  • Dan Ebberts

    July 5, 2021 at 3:02 pm

    Something like this maybe:

    n = 0;

    cb = effect("VIDEO_3")("Checkbox");

    if (cb.numKeys > 0){

    n = cb.nearestKey(time).index;

    if (time < cb.key(n).time) n--;

    }

    if (n > 0){

    cb.value ? linear(time, cb.key(n).time, cb.key(n).time + framesToTime(20),-100,0) : -100;

    }else{

    cb.value ? 0 : -100;

    }

  • Paulius v Ruksa

    July 5, 2021 at 3:22 pm

    This works great!

    It will save me so much time and so many keyframes, this is exactly what I needed.

    Thanks a lot Dan!

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