-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathsortByPosition.jsx
53 lines (42 loc) · 1.69 KB
/
sortByPosition.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
//snippet used to sort layers depending on their position, left to right
var sortByPosition = this
sortByPosition.go = function(type){
//type is "left", "right", "top" or "bottom"
//whick stands for left to right, right to left, top to bottom, bottom to top respectively
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
var sel = activeComp.selectedLayers;
if(type == "left" || type == "right"){
sel.sort(function(a,b){
if(a.transform.position.value[0] <= b.transform.position.value[0]){
if(type == "left") return 1;
else return -1;
}
else if(a.transform.position.value[0] > b.transform.position.value[0]){
if(type == "left") return -1;
else return 1;
}
else return 0;
});
}
if(type == "top" || type == "bottom"){
sel.sort(function(a,b){
if(a.transform.position.value[1] <= b.transform.position.value[1]){
if(type == "top") return 1;
else return -1;
}
else if(a.transform.position.value[1] > b.transform.position.value[1]){
if(type == "top") return -1;
else return 1;
}
else return 0;
});
}
app.beginUndoGroup("sort")
for(var s = 1; s<sel.length; s++){
sel[s].moveBefore(sel[s-1])
}
app.endUndoGroup()
}
}
sortByPosition.go("left")