-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortLayers.jsx
71 lines (63 loc) · 2.09 KB
/
sortLayers.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
(function() {
var comp = app.project.activeItem;
if (!comp || !(comp instanceof CompItem)) {
alert('No active composition.');
return;
}
app.beginUndoGroup('Sort Layers');
var topLayersCamera = [];
var topLayersLo = [];
var topLayersPANTUSL = [];
var bottomLayersBook = [];
var bottomLayersBG = [];
var bottomLayersSolid = [];
var middleLayers = [];
var regexCamera = /camera/i;
var regexLo = /lo/i;
var regexPANTUSL = /PAN|TU|SL/i;
var regexBook = /BOOK/i;
var regexBG = /BG/i;
var regexSolid = /Solid /i;
for (var i = 1; i <= comp.numLayers; i++) {
var layer = comp.layer(i);
var name = layer.name;
if (regexCamera.test(name)) {
topLayersCamera.push(layer);
} else if (regexLo.test(name)) {
topLayersLo.push(layer);
} else if (regexPANTUSL.test(name)) {
topLayersPANTUSL.push(layer);
} else if (regexBook.test(name)) {
bottomLayersBook.push(layer);
} else if (regexBG.test(name)) {
bottomLayersBG.push(layer);
} else if (regexSolid.test(name)) {
bottomLayersSolid.push(layer);
} else {
middleLayers.push(layer);
}
}
// Case-insensitive sorting for middle layers
middleLayers.sort(function(a, b) {
var nameA = a.name.toLowerCase();
var nameB = b.name.toLowerCase();
return nameB.localeCompare(nameA);
});
function reorderLayers(layersArray) {
for (var i = 0; i < layersArray.length; i++) {
var layer = layersArray[i];
for (var j = layer.index; j > i + 1; j--) {
layer.moveBefore(comp.layer(j - 1));
}
}
}
// Reordering process
reorderLayers(bottomLayersSolid.reverse());
reorderLayers(bottomLayersBG.reverse());
reorderLayers(bottomLayersBook.reverse());
reorderLayers(middleLayers);
reorderLayers(topLayersPANTUSL.reverse());
reorderLayers(topLayersLo.reverse());
reorderLayers(topLayersCamera.reverse());
app.endUndoGroup();
})();