Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Percentual progress, in time, between previous and the next keyframe issue

  • Percentual progress, in time, between previous and the next keyframe issue

    Posted by Mikael Holmström on October 8, 2014 at 9:05 pm

    Hi folks,

    New to expressions, I’d like to calculate the percentual progress, in time, between previous and next keyframe. The ’p’ value below seems to return the accurate result, at first. Then the numbers goes red and I get this error message:

    ”After Effects warning: an expression was disabled as a result of an error.
    Error at line 0 in property ’Position’ of layer 11 (’test layer’) in comp ’test’.
    invalid numeric result (divided by zero?).”

    Why, anyone? It was not divided by zero as the error message suggests.

    Thanks,
    Mikael

    nearKey = thisLayer.position.nearestKey(time).index;
    lastKey = (thisLayer.position.key(nearKey).time>time) ? ((nearKey>1) ? nearKey-1 : nearKey) : nearKey;
    nextKey = (lastKey<thisLayer.position.numKeys) ? lastKey+1 : lastKey;

    lastTime = timeToFrames(thisLayer.position.key(lastKey).time);
    nextTime = timeToFrames(thisLayer.position.key(nextKey).time);

    durationInFrames = nextTime-lastTime;
    progressInFrames = timeToFrames(time)-lastTime;
    progress = progressInFrames/durationInFrames;

    p = (progressInFrames/durationInFrames)*100;

    [p, p]

    Mikael Holmström replied 11 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 8, 2014 at 11:08 pm

    I think your durationInFrames will be zero after the last keyframe. Also, I’m not sure your logic works quite right if you have times before the first keyframe.

    Dan

  • Mikael Holmström

    October 9, 2014 at 6:13 am

    You are right, it will be zero at som point in time of the comp. I did not know that Expressions would react on that. Thanks Dan, now I probably will find a way to work around the problem.
    Mikael

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