Quick Loop

All things .jsx

Moderator: Paul Tuersley

Post Reply
Klustre
Posts: 21
Joined: July 27th, 2011, 2:53 am

October 10th, 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).

Code: Select all

/*

	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 652 times
Post Reply