ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Stop loop expression at certain time period

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Krishna Moorthy
Stop loop expression at certain time period
on May 3, 2017 at 12:21:51 pm

I have created a looping animation using the expression,


as I want only the last two keyframes to loop. Now, the solution am looking for is to stop the loop at some point of time of my choice. Am sure that, it can be done by tweaking the above expression a little. Kindly, anyone help me with the issue. Will provide additional information, if above details are not clear.

Thank in advance.

loopOut(type = "pingpong", numKeyframes = 1)


Return to posts index

Kevin Camp
Re: Stop loop expression at certain time period
on May 3, 2017 at 9:05:09 pm

I think you'll need to roll-your-own loop expression.

try this:

dur = 5; // value in seconds
if ( numKeys > 0 ) {
loopDur = key(numKeys).time - key(1).time;
if ( time &lt; dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur );
}


Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Krishna Moorthy
Re: Stop loop expression at certain time period
on May 5, 2017 at 6:21:50 am

Hi,, Thanks for your reply mate.

AE throws an error when I used your expression, the error is, "expected )"

Could you please explain the expression, so that I can figure out what is the issue with it.

Thank you!


Return to posts index


Kevin Camp
Re: Stop loop expression at certain time period
on May 5, 2017 at 2:12:27 pm

the less-than sign was replaced by '<' when posting...

I also should have added the 'else' in case there were no keyframes.... i'll try the expression with a performated tag:

dur = 5; // value in seconds
if ( numKeys > 0 ) {
loopDur = key(numKeys).time - key(1).time;
if ( time < dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur );
} else {
value;
}


essentially the expression is using the valueAtTime() function to build a loop. by using the modulus (that's the % sign function) of the current time for a given period (in this case loopDur, that is derived by the times of the first an last keyframes), you can create your own looping expression.

using the if statement, it will loop until the time specified by the 'dur' variable.

valueAtTime( due % loopDur ) just sets the value (or point in the loop) to hold at that time specified by 'dur'.

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Suhair Vennakkad
Re: Stop loop expression at certain time period
on Dec 27, 2017 at 8:29:17 am

thank you Kevin Camp_it's very usefull

dur = 15; // value in seconds

if ( numKeys > 0 ) {

loopDur = key(numKeys).time - key(1).time;

if ( time &lt; dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur );

} else {

value;

}


Return to posts index

Colby Turybury
Re: Stop loop expression at certain time period
on Jun 16, 2018 at 8:55:31 pm

How about the looping be based on number of loops instead of time. Say 10 loops. How would you go about that?


Return to posts index


Dan Ebberts
Re: Stop loop expression at certain time period
on Jun 17, 2018 at 1:02:36 pm

That would be something like this:


nLoops = 10;
if (numKeys > 1){
loopDur = key(numKeys).time - key(1).time;
n = Math.floor((time - key(1).time)/loopDur);
if (n < nLoops){
t = (time - key(1).time)%loopDur;
valueAtTime(key(1).time + t);
}else{
valueAtTime(key(numKeys).time);
}
}else
value;



Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]