Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to count up every X amount of frames

  • Expression to count up every X amount of frames

    Posted by Aoife Mccarthy on June 18, 2020 at 5:32 pm

    Hi all!

    I’m currently working on an animated data visualisation, and I’m having issues syncing up my animated timeline with my data points on the chart. The timeline looks like this:

    The marker moves along the timeline from left to right, whilst the day marker to the right counts up.

    In the expression for the data points, each day has a duration of 3 frames. So 0:00:00:00 = val1, 0:00:00:03 = val2, 0:00:00:06 = val3 etc.

    I’ve used a slider control for the day marker (setting start and end values to 1 and 29/30/31 respectively), with this expression in Source Text:

    Math.round(effect("Slider Control")("Slider"))

    However it doesn’t exactly sync up with the data – some days get 4 frames, some get 3 etc. Is it a rounding issue?

    I think I need to create some kind of integer counter that counts up every 3 frames exactly – can anybody help?

    Aoife Mccarthy replied 5 years, 11 months ago 3 Members · 5 Replies
  • 5 Replies
  • Aoife Mccarthy

    June 18, 2020 at 8:24 pm

    If it helps, this is how I’ve managed to get it working with keyframes… there must be a way to automate this though!

  • Dan Ebberts

    June 18, 2020 at 9:39 pm

    I’m not clear on what you’re doing, but something like this might fit in there somewhere:

    Math.floor(effect(“Slider Control”)(“Slider”)/3)*3

    Dan

  • Aoife Mccarthy

    June 19, 2020 at 8:41 am

    Hi Dan, thanks for your suggestion. That’s not quite what I need though – I’ve just tried it out and it’s counting up in 3’s, I need it to increment by 1.

    Basically what I need is a counter that counts up from 1 – 30, with each number having an exact 3 keyframe duration. I think my issue with using a slider is I end up dealing with floating point precision, which makes the distribution of keyframes slightly uneven.

    I’ve achieved it manually by using toggle hold keyframes on the slider property, ie 0:00:00:00 → Slider = 1, 0:00:00:03 → Slider = 2, 0:00:00:03 → Slider = 3 etc.

    Does that make sense? Let me know if there’s any other salient points I’ve missed!

  • Robert Müller

    June 19, 2020 at 9:40 am

    Hi, this should do what you are looking for

    t=timeToFrames();
    frameStep=3;
    days=30;
    Math.floor(t/frameStep)%days+1

    this counts to 30 (or any number you put for “days”) every 3 frames (or any number you put for “frameStep”), starting at 1 and resetting back to 1 after 30.
    If you want to stop at 30 try this:
    t=timeToFrames();
    frameStep=3;
    f=Math.floor(t/frameStep)+1;
    if (f>30){30}else{f};

  • Aoife Mccarthy

    June 19, 2020 at 11:59 am

    Hi Robert – that’s it! Thanks a million

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