Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need to trigger animation any time there is a marker.

  • Need to trigger animation any time there is a marker.

    Posted by Kavon Zamanian on January 9, 2019 at 9:12 pm

    I’m building a template with the goal of the user being able to trigger an animation with one marker. This way all they need to do is add a marker where on the timeline they want the animation to trigger. I don’t want sets of in/out markers – I just want the animation to trigger anytime there’s a marker at all so users have unlimited executions of this animation.

    I have it working for specific markers – just missing a reference that I can’t seem to hunt down. This is what I have so far for one property.

    This works fine for the first marker, or any other specific one, but I want to extend it to all markers so that it triggers once for every one.

    Additionally, I’d love a way to apply this to actual keyframes, perhaps by time-remapping a composition. This way I wouldn’t be limited to the ease expression for my repeating animations. That’s a bit over my head though.

    Thanks in advance.

    m = thisComp.marker.key(1).time;
    ease(time, m, m + 1,[-200],[0]);

    Julian Chojnacki replied 3 years, 6 months ago 6 Members · 20 Replies
  • 20 Replies
  • Dan Ebberts

    January 9, 2019 at 10:41 pm

    Probably something like this, but I’m not sure what the “nomal” (non-animating state) should be (set by the last line):


    m = thisComp.marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }
    if (n > 0){
    t = m.key(n).time;
    ease (time,t,t+1,-200,0);
    }else
    0

    Dan

  • Kavon Zamanian

    January 10, 2019 at 5:46 pm

    This is perfect. Thank you so much!

  • Kavon Zamanian

    January 10, 2019 at 7:38 pm

    Hey Dan,

    I realized I’m still missing something and was wondering if you could help further. One of my animations would have 3 keyframes which I don’t think I can apply to a kind of 3-stage ease expression (perhaps I’m wrong). Regardless, I think the better approach would be to apply it to a time-remapped composition in hopes of every marker re-triggering that composition playback.

    https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=38304&univpostid=38304&pview=t

    I found this thread where you helped someone do something similar, but I’m having trouble tweaking the code accordingly. Thoughts?

    Thanks again

  • Dan Ebberts

    January 10, 2019 at 7:55 pm

    Like this maybe:


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

    Dan

  • Kavon Zamanian

    January 10, 2019 at 7:58 pm

    Again, perfect. This project wouldn’t be possible without you.

    Cheers.

  • Paul Roper

    November 11, 2021 at 4:58 pm

    I realise this post was from some time ago, but I have a similar question, but simpler:
    All I need to do, is get the index of a marker AT THE CURRENT TIME, not that fairly annoying/useless “nearestKey” thing, which changes whenever the current time is kinda near the marker, not ON the marker. I’m guessing the (somewhat convoluted) way of going about it would be:
    1. Get the TIME of the nearestKey

    2. When the current time >= the nearestKey’s time, use that nearestKey’s index

    …or something. Basically, all I want to do is be able to control the appearance, word-by-word, of a text layer, and be able to trigger that by hammering in a load of markers (easily done with a text animator/opacity/based on words). But getting the “nearestKey” to be “exactKey” is a right pain!
    Any ideas/help would be greatly appreciated, please!

    ~ Paul

    UPDATE: From a bit more hunting around here, I found something by @Meng Zhiqun, and pinched a bit of expression from there. It generates an error if the time is before the first marker, but I can live with that:

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

    All seems quite convoluted to just get the index of the current marker!

  • Julian Chojnacki

    October 21, 2022 at 1:31 pm

    Hi Dan, this expression is a gem for subtitles! I’m curious, is it possible to use the next marker as an endpoint for the ease animation instead of using “t+1”?

  • Dan Ebberts

    October 21, 2022 at 3:36 pm

    Sure, but what should happen at the last marker?

  • Julian Chojnacki

    October 21, 2022 at 11:24 pm

    Thanks for the fast reply!

    Basically, I’m using the expression below to animate subtitles with text animators using Source Text keyframes. It works perfectly! On single words to be specific. But when it comes to longer sentences, I’d love to have the ability to stretch the ease animation to the next sentence/Source Text keyframe, so that the text is roughly synced with the audio. The ease expression values are driving the range selectors “Start”.

    Best
    Julian

    m = text.sourceText;

    if (m.numKeys > 0){

    n = m.nearestKey(time).index;

    if (m.key(n).time > time) n--;

    }

    if (n > 0){

    t = m.key(n).time;

    t2 = n + m.key(n).time;

    ease (time,t,t+.5,0,100);

    }else

    0

  • Dan Ebberts

    October 22, 2022 at 12:21 am

    This would animate between the keyframes, except for the last one, where it would use your previous timing:

    m = text.sourceText;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }
    if (n > 0){
    t1 = m.key(n).time;
    if (n < m.numKeys){
    t2 = m.key(n+1).time;
    }else{
    t2 = t1 + .5;
    }
    ease (time,t1,t2,0,100);
    }else
    0
Page 1 of 2

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