Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Peak value calculation

  • Peak value calculation

    Posted by Vince Babbra on January 25, 2018 at 6:16 pm

    Simplifying my last post…

    Let’s say I have a 2 second composition with a layer that has bunch of keyframes on a property, say it’s y position.

    I can use the below expression to return me the highest value of all the keyframes in the layer:

    How can I adapt it so that it returns the highest value of the keyframes in that layer… but only up till that point in time?

    thx

    a = thisComp.layer("Layer1").transform.yPosition;
    max = 0;
    for(i = 1;i<=a.numKeys;i++){
    max = Math.max(max, a.key(i).value);
    }
    max

    Vince Babbra replied 8 years, 7 months ago 3 Members · 9 Replies
  • 9 Replies
  • Andrei Popa

    January 25, 2018 at 10:15 pm

    This should work.
    a =thisComp.layer("Shape Layer 1").transform.yPosition
    max = 0;
    for(i = 1;i<=a.numKeys;i++){
    if (a.key(i).time <= time) max = Math.max(max, a.key(i).value);
    }
    max

    Andrei
    My Envato portfolio.

  • Dan Ebberts

    January 25, 2018 at 10:20 pm

    I’d try it this way:


    a = thisComp.layer("Layer1").transform.yPosition;
    max = a.value;
    for (i = 1; i <= a.numKeys; i++){
    if (time < a.key(i).time) break;
    max = Math.max(max,a.key(i).value);
    }
    max

    Dan

  • Vince Babbra

    January 25, 2018 at 10:33 pm

    This works perfect guys… thank you so much… One final question, if I wanted the inverse, I wanted it to output the MINIMUM value instead, what would I need to change!?

    Thx so much!

  • Andrei Popa

    January 25, 2018 at 10:44 pm

    You should use Math.min instead of Math.max

    Andrei
    My Envato portfolio.

  • Vince Babbra

    January 25, 2018 at 10:48 pm

    Hmm, using Math.min instead of Math.max does not work? It just returns a single value…

  • Andrei Popa

    January 25, 2018 at 11:24 pm

    Maybe the first value is tha absolute minimum… I have just tried it and it work on my side.

    Andrei
    My Envato portfolio.

  • Vince Babbra

    January 25, 2018 at 11:45 pm

    This is very strange. Please see here, what am I doing wrong?

    https://www.dropbox.com/s/xcso312gkk2i6o0/Math%20Min%20Problem.mp4?dl=0

    Thanks in advance!

  • Andrei Popa

    January 26, 2018 at 8:32 am

    You will have to excuse my delay, i had to go to sleep and just got to the office right now. I have tested it with Dan’s expression and worked. The difference is that in my expression, i initiate the min with 0, which stays the minimum for all the duration. That is why it didn’t work. The big difference between Dan’s expression and mine is that his shows the value as it changes, while mine just snaps when getting to the keyframe. I recommend you try both. So for mine to work just change min initialization and use Math.mina =thisComp.layer("Shape Layer 1").transform.opacity
    max = a.key(1).value;
    for(i = 1;i<=a.numKeys;i++){
    if (a.key(i).time <= time) max = Math.max(max, a.key(i).value);
    }
    max

    Andrei
    My Envato portfolio.

  • Vince Babbra

    January 26, 2018 at 2:19 pm

    This works! Thanks so much to both of you. Incredible!

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