Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions compare current time with the nearest marker time expression issue.

  • compare current time with the nearest marker time expression issue.

    Posted by Michael Song on June 6, 2017 at 8:50 am

    Hi all,

    I want to move a text layer above for a fixed amount of pixels when it hits the marker.
    I write this expression in the Position property of the text layer
    if ( time == thisComp.marker.nearestKey(time).time ) {
    value+=[0,40];}

    But After Effects always shows an expression error for it.
    What’s the problem with this expression?
    Thanks!

    Michael Song replied 9 years ago 3 Members · 9 Replies
  • 9 Replies
  • Chris Scalzo

    June 6, 2017 at 2:11 pm

    did you want it to move if it is greater than that time or exactly at that time? (note, it might not be exactly at that time on any frame)

  • Michael Song

    June 6, 2017 at 2:20 pm

    exactly at that time

  • Chris Scalzo

    June 6, 2017 at 2:28 pm

    Maybe something like this would work for you. (sorry working on 3 others things and no time to test.

    if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time ) {
    value+=[0,40];}

  • Chris Scalzo

    June 6, 2017 at 2:30 pm

    I forgot to round both numbers off.. try this.

    if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
    value+=[0,40];}

  • Michael Song

    June 6, 2017 at 2:37 pm

    Thanks. So I guess what’s wrong with my original expression is that it compares two values that are not of the same type. So they can not be compared until they are turned into the same type. Is this correct?

  • Chris Scalzo

    June 6, 2017 at 3:11 pm

    I assumed the rounding error would increase the likelihood that you wouldn’t hit that exact time ever.

    eg. if you set keyframe at 10s the value of “time” wouldn’t be exactly 10.

    try creating a text layer and in the text source at the expressions”time”. go to 10 seconds and you will see what I mean. Plus your expression wouldn’t add that value permanently to the value. just when it hit that time exactly and would change back. if you count the markers with some type of nummarkers expression you could add the to the value when greater than nearest marker your amount you wanted to add times the number of markers you passed.

    If I am incorrect, someone please correct me.

  • Michael Song

    June 7, 2017 at 12:44 am

    if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
    value+=[0,40];}

    AE still shows as error. Any idea?

  • Santi Agustí

    June 7, 2017 at 3:20 am

    I think this answer may lead you to a solution: https://forums.creativecow.net/thread/227/30151
    (and the easeFrames is pretty cool, so you can have a smooth transition, or just change that value with 0 for a jump)

    just change the last line of Philip Neve’s code to make it work on Y, so it can be:


    offsetAmt = 40;
    easeFrames = 10;
    n = 0;
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time) n--;
    }
    yOffset = 0;
    if (n > 0){
    t = time - marker.key(n).time;
    yOffset = easeOut(t,0,framesToTime(easeFrames),(n-1)*offsetAmt,n*offsetAmt);
    }
    [value[0],value[1] + yOffset];

  • Michael Song

    June 7, 2017 at 4:01 am

    I think I might find out the issue.
    The Position property expects an array(if you don’t split it). So the IF condition in expression has to have an array return value if the condition isn’t fulfilled.

    if ( time.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
    value+=[0,40];}else{value;}

    Also you don’t need time.value to work. time.toFixed(3) works just by itself.

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