-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverseOrder.jsx
34 lines (27 loc) · 1.02 KB
/
reverseOrder.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
(function() {
var comp = app.project.activeItem; // Get the active composition
if (!comp || !(comp instanceof CompItem)) {
alert('Please select a composition.');
return;
}
app.beginUndoGroup('Reverse Selected Layers'); // Begin undo group
var selectedLayers = [];
var indices = [];
// Loop through the selected layers and store them in an array
for (var i = 1; i <= comp.selectedLayers.length; i++) {
var layer = comp.selectedLayers[i - 1];
selectedLayers.push(layer);
indices.push(layer.index);
}
// Sort indices in ascending order to handle them from bottom to top
indices.sort(function(a, b) { return a - b; });
for (var j = 0; j < selectedLayers.length; j++) {
// Move each layer to the correct position based on the reversed order
try {
selectedLayers[j].moveBefore(comp.layer(indices[indices.length - j - 1]));
} catch(e) {
//nothing
}
}
app.endUndoGroup(); // End undo group
})();