-
Notifications
You must be signed in to change notification settings - Fork 22
/
Sort Layers By Time.jsx
42 lines (34 loc) · 966 Bytes
/
Sort Layers By Time.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
/**
* Sorts selected layers based on their in points, ascending.
*
* Modifiers:
* - Hold SHIFT to sort descending.
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function sortLayersByTime() {
var DESCENDING = ScriptUI.environment.keyboardState.shiftKey;
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert("Please select a composition!");
return;
}
var layers = comp.selectedLayers;
if (layers.length === 0) {
alert("Please select some layers!");
return;
}
app.beginUndoGroup("Sort Layers By In Point");
layers.sort(function (layerA, layerB) {
if (layerA.inPoint < layerB.inPoint) {
DESCENDING ? layerA.moveBefore(layerB) : layerA.moveAfter(layerB);
return -1;
} else if (layerA.inPoint > layerB.inPoint) {
DESCENDING ? layerA.moveAfter(layerB) : layerA.moveBefore(layerB);
return 1;
}
return 0;
});
app.endUndoGroup();
})();