-
Notifications
You must be signed in to change notification settings - Fork 33
/
sort-l-to-r.jsx
45 lines (39 loc) · 956 Bytes
/
sort-l-to-r.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
// sort-l-to-r.jsx
// sort layers from left to right
(function(thisObj) {
var compare = function(a, b) {
if(a.xy[0] < b.xy[0]) {
return -1;
}
if(a.xy[0] > b.xy[0]) {
return 1;
}
return 0;
};
var main = function() {
var proj = app.project;
var curComp = proj.activeItem;
if (!curComp || !(curComp instanceof CompItem)) {
alert('noComp');
return;
}
var arr = [];
for (var i = 0; i < curComp.selectedLayers.length; i++) {
var l = curComp.selectedLayers[i];
var pos = l.transform.position.value;
arr.push({layer: l, xy: pos});
}
// ~ $.writeln(arr.toSource());
arr.sort(compare);
$.writeln('------------------');
// ~ $.writeln(arr.toSource());
for(var j = 0; j < arr.length; j++) {
arr[j].layer.moveToEnd();
}
// $.writeln("layername\n"+arr.join ("\n"));
};
var run = function(f) {
f();
};
run(main);
}(this));