forked from zlovatt/zl_Scriptlets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loop Selected Layers.jsx
66 lines (56 loc) · 1.73 KB
/
Loop Selected Layers.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
/**
* Enables time remapping on selected layers, and adds a loopOut("cycle") to loop the layer.
*
* Modifiers:
* - Hold CTRL to loop IN instead of loop OUT
* - Hold SHIFT to PINGPONG instead of CYCLE
* - Hold both to loop IN, with PINGPONG
*
* @author Zack Lovatt <zack@lova.tt>
* @version 0.2.1
*/
(function loopSelectedLayers() {
/**
* Loops selected layer
*
* @param {string} direction Loop type, one of 'loopIn' or 'loopOut'
* @param {string} method Loop method, one of 'cycle'/'pingpong'
*/
function loopSelected(direction, method) {
var loopExpression = direction + "('" + method + "');";
var comp = app.project.activeItem;
var layers = comp.selectedLayers;
for (var ii = 0, il = layers.length; ii < il; ii++) {
var curLayer = layers[ii];
if (curLayer.canSetTimeRemapEnabled !== true) {
alert(curLayer.name + ' can not be looped!');
continue;
}
// 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) - comp.frameDuration
);
curLayer.timeRemap.removeKey(3);
curLayer.outPoint = comp.duration;
}
}
var direction = 'loopOut';
var method = 'cycle';
// If ctrl, loopIn instead of loopOut.
if (
ScriptUI.environment.keyboardState.ctrlKey ||
ScriptUI.environment.keyboardState.metaKey
) {
direction = 'loopIn';
}
// Shift = pingpong
if (ScriptUI.environment.keyboardState.shiftKey) {
method = 'pingpong';
}
app.beginUndoGroup('Loop Selected Layers');
loopSelected(direction, method);
app.endUndoGroup();
})();