forked from zlovatt/zl_Scriptlets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloopSelectedLayers.jsx
74 lines (52 loc) · 2.25 KB
/
loopSelectedLayers.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**********************************************************************************************
loopSelectedLayers
Copyright (c) 2017 Zack Lovatt. All rights reserved.
Name: Loop Selected Layers
Version: 0.2
For use w/ ft-toolbar or other script runners.
This will run through all selected layers, enable time remap,
and add cycle loop -- all in one click.
If the wrong thing is selected or layer can't be remapped,
user will be alerted of the fact.
MODIFIERS
Hold CTRL to loop IN instead of loop OUT
Hold SHIFT to PINGPONG instead of CYCLE
Combine ctrl w/ shift to merge alternatives.
Originally requested by Andrew Embury (aembury.com)
This script is provided "as is," without warranty of any kind, expressed
or implied. In no event shall the author be held liable for any damages
arising in any way from the use of this script.
**********************************************************************************************/
(function loopSelectedLayers () {
function loopSelected (loopOption, loopFunction){
var loopExpression = loopOption + "('" + loopFunction + "');";
var thisComp = app.project.activeItem;
var userLayers = thisComp.selectedLayers;
for (var i = 0; i < userLayers.length; i++) {
var curLayer = userLayers[i];
if(curLayer.canSetTimeRemapEnabled === true){
// Enable time remap, set it to the expression
curLayer.timeRemapEnabled = true;
curLayer.timeRemap.expression = loopExpression;
// Add new key, remove last key
curLayer.timeRemap.addKey(curLayer.timeRemap.keyTime(2)-thisComp.frameDuration);
curLayer.timeRemap.removeKey(3);
curLayer.outPoint = thisComp.duration;
} else {
alert (curLayer.name + " can not be looped!");
} // end if canSetTimeRemap
} // end for numLayers
} // end function loopOutSelected
app.beginUndoGroup("Loop Selected Layer");
var loopOption = "loopOut";
var loopFunction = "cycle";
// If ctrl, loopIn instead of loopOut.
if ((ScriptUI.environment.keyboardState.ctrlKey) || (ScriptUI.environment.keyboardState.metaKey))
loopOption = "loopIn";
// Shift = pingpong
if (ScriptUI.environment.keyboardState.shiftKey)
loopFunction = "pingpong";
loopSelected(loopOption, loopFunction);
app.endUndoGroup();
})();