Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
Klustre
Topic Author
Posts: 21
Joined: Wed Jul 27, 2011 2:53 am

Quick Loop

Wed Oct 10, 2012 4:47 am

Quick Loop:
  • adds a Time Remap to the selected layers
  • adds a loopOut("cycle"); to the Remap
  • sets a new keyframe before the last
  • and removes the last (blank) keyframe

So that the layer loops smoothly without a blink in between each loop. A friend of mine requested this one, because he's about to do an animation having to loop a lot of comps. For footage items you might just want to use the loop feature in the interpret footage window.

Quick Loop is framerate independent and was tested on CS5 and CS6 (OSX).

/*

   QUICK LOOP—
   ADDS A TIMEREMAP TO THE SELECTED LAYERS, APPLIES
   A LOOPOUT() AND MAKES SURE IT LOOPS WITHOUT A
   BLANK KEYFRAME AT THE END OF EACH LOOP.
   FRAMERATE INDEPENDENT.

   WRITTEN BY REMCO JANSSEN / KLUSTRE
   KLUSTRE.NL / OCTOBER 2012
   
   REQUESTED BY TOM SCHROOTEN

*/


function quickLoop(thisObj) {
   
   var quickLoopData = new Object();
   
   quickLoopData.scriptVersion = "1.0";
   quickLoopData.scriptName    = "Quick Loop";
   quickLoopData.fullName      = quickLoopData.scriptName + " " + quickLoopData.scriptVersion;
   
   quickLoopData.strUndoGroup  = "Quick Loop";
   
   quickLoopData.strExpression = "loopOut(\"cycle\");";
   quickLoopData.strApplied    = ": applied " + quickLoopData.scriptName;
   quickLoopData.strSkip       = ": skipped. Couldn't enable Time Remap.";
   quickLoopData.strDone       = [quickLoopData.scriptName + "ing Done!\nSuccessfully Quick Looped ", " layer(s).", "\n\nIt skipped ", " layer(s), because Time Remap couldn't be enabled."];
   
   quickLoopData.errNoLayer    = "Invalid Selection\nPlease select at least one layer.";
   quickLoopData.errVersion    = "Untested Version\nThis script was tested on CS5 and CS6 only. Errors may occur.";
   

   if (parseFloat(app.version) < 10.0){
      alert(quickLoopData.errVersion);
   }

   if (!app.project || !(app.project.activeItem instanceof CompItem) || app.project.activeItem.selectedLayers == null || app.project.activeItem.selectedLayers < 1) {
      alert (quickLoopData.errNoLayer);
   }else{

      var loopComp          = app.project.activeItem;
      var loopLayers        = loopComp.selectedLayers;
      var loopKey;
      var loopAppliedLayers = new Array();
      var loopSkippedLayers = new Array();
      var loopFrame         = loopComp.frameDuration;
      
      app.beginUndoGroup(quickLoopData.strUndoGroup);   
      
      for (var i=0; i < loopLayers.length; i++) {
         if(loopLayers[i].canSetTimeRemapEnabled == true){
            loopLayers[i].timeRemapEnabled = true;
            loopLayers[i].timeRemap.expression = quickLoopData.strExpression;
            loopKey = loopLayers[i].timeRemap.keyTime(2);
            loopLayers[i].timeRemap.addKey(loopKey-loopFrame);
            loopLayers[i].timeRemap.removeKey(3);
            writeLn(loopLayers[i].name + quickLoopData.strApplied);
            loopAppliedLayers.push(loopLayers[i].name);            
         }else{
            writeLn(loopLayers[i].name + quickLoopData.strSkip);
            loopSkippedLayers.push(loopLayers[i].name);
            continue;
         }
      }
   
      app.endUndoGroup();
      
      if (loopSkippedLayers.length > 0){
         alert(quickLoopData.strDone[0] + loopAppliedLayers.length + quickLoopData.strDone[1] + quickLoopData.strDone[2] + loopSkippedLayers.length + quickLoopData.strDone[3]);
      }else{
         alert(quickLoopData.strDone[0] + loopAppliedLayers.length + quickLoopData.strDone[1]);
      }
   }
}

quickLoop();
Attachments
kl_quickLoop.jsx.zip
(1.58 KiB) Downloaded 569 times

Who is online

Users browsing this forum: No registered users and 3 guests