How to loop path in After Effects?

I ran into trouble looping the path in after-effects and after googling out I found a solution in Aejuice. They have created a simple script, you just need to copy and paste it into your expression.

To enable expression you need to alt+click on the stopwatch to activate the expression editor panel.

alt+click to enable the expression panel

Script to loop a path without ping-pong attributes

// if you don't need pingpong - false
 pingPong = false;
 try{
   // start - first keyframe
   timeStart = thisProperty.key(1).time; 
   // count duration
   duration = thisProperty.key(thisProperty.numKeys).time - timeStart; 
   // cycle number
   quant = Math.floor((time - timeStart) / duration); 
   if (quant < 0) quant = 0 // != 0
   if (quant % 2 == 1 && pingPong == true){ 
 	t = 2 * timeStart + (quant+1) * duration - time; 
   } else { 
 	t = time-quant*duration;
   }
 } catch(e) {
   t = time;
 }
 thisProperty.valueAtTime(t);
This expression works in the same way as a standard loop cycle expression below.
loopOut(type="cycle");

Script to loop a path with ping-pong attributes

// if you don't need pingpong - false
pingPong = true;
try{
  // start - first keyframe
  timeStart = thisProperty.key(1).time; 
  // count duration
  duration = thisProperty.key(thisProperty.numKeys).time - timeStart; 
  // cycle number
  quant = Math.floor((time - timeStart) / duration); 
  if (quant < 0) quant = 0 // !=0
  if (quant % 2 == 1 && pingPong == true) { 
    t = 2 * timeStart + (quant + 1) * duration - time; 
  } else { 
    t = time - quant * duration;
  }
} catch(e) {
  t = time;
}
thisProperty.valueAtTime(t);
This expression works in the same way as a standard loop cycle expression below.
loopOut(type="pingpong");
Facebook
Twitter
LinkedIn

Other Posts