Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions counter expression

  • counter expression

    Posted by Adrian Agheniței on March 17, 2025 at 8:34 pm

    Hi. I have a value that is rounded to 0 and 1, coresponding to the beats of a song.

    I would like to count each time the value touch 1. i guess it should be a loop expression that ends with a i++ if (n==1).

    Any help is more than welcomed.

    Thank you

    Roland R. kahlenberg replied 1 month, 1 week ago 3 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 17, 2025 at 8:52 pm

    This should work, but there might be a more efficient way to do it, depending on what’s driving your value (for this example, I’m assuming the value is contained in a slider):

    s = effect("Slider Control")("Slider");
    f = timeToFrames(time);
    above = s.valueAtTime(0) >= 1;
    n = above ? 1 : 0;
    for (i = 1; i <= f; i++){
    if (above){
    if (s.valueAtTime(framesToTime(i)) < 1){
    above = false;
    }
    }else{
    if (s.valueAtTime(framesToTime(i)) >= 1){
    n++;
    above = true;
    }
    }
    }
    n
  • Roland R. kahlenberg

    March 18, 2025 at 2:39 am

    An efficient workflow will be to leave the Expression as is and then use a script to do the counting. Again, this may be more efficient OR NOT depending on your workflow.

    My thoughts are to let Expressions do quick calculations and then use scripts to perform one-off calculations – as a rule of thumb.

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