• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Possible to Set a Limit to loopOut Cycles?

Explorer ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

I've got a composition with a few layers of precomps. I enabled Time Remapping on each and added this script:
loopOut(loop="cycle",numKeyframes=0)
Works great. I'd love to be able to limit the number of times the animation loops, though. Is that possible?
Thanks much!

TOPICS
Expressions , How to , Scripting

Views

101

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

Try this instead of loopOut():

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

Dan! That's brilliant. Thanks SO much! Works like a charm.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

LATEST

Dan's solution is elegant, but I think this one is more useful.

 

If the first and last frames of the nested comp are identical so you can have an identical loop, and you went to the last Time Remapping keyframe, moved back one frame, set a new TR keyframe, then deleted the last one, so you have a perfect seamless loop try this:

 

Time remapping works internally on frame numbers. If you convert time to frame numbers, you can multiply the frame number of the Time Remapping keyframe by the number of loops you want. Combine that with an if statement, and you get this.

 

 

fr = time / thisComp.frameDuration;
t = key(2).time / thisComp.frameDuration;
nL = 8
if (fr < t * nL)
	loopOut();
else
	0

 

 

 

That expression will loop the animation eight times and then stop. You can also slide the last TR keyframe left or right in the timeline to change the speed of the loop without modifying the expression.

 

I attached a sample comp.

 

It also works with loopOut("ping-pong"). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines