-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_get_reposition.jsx
50 lines (34 loc) · 1.13 KB
/
2_get_reposition.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
#include "functions/json2.js";
#include "../bystram_file_paths.js";
// Open file: bystram_skeleton_trimmed.ai
// Run this step once to get the new positions of nodes on the tree
var out_file = new File(reposition_path)
// Get document
var doc = app.activeDocument;
var skel = doc.layers.getByName('Skeleton')
var skel_nodes = skel.layers.getByName('Nodes')
var interval = 25
var reposition = {}
function get_centre(bounds){
return [((bounds[2] - bounds[0]) / 2) + bounds[0], ((bounds[3] - bounds[1]) / 2) + bounds[1]]
}
// Minimum left
lefts = []
for(var i = 0; i < skel_nodes.groupItems.length; i++){
node = skel_nodes.groupItems[i]
lefts.push(get_centre(node.geometricBounds)[0])
}
lefts.sort(function(a, b) {return a - b;})
min_left = lefts[0]
for(var i = 0; i < skel_nodes.groupItems.length; i++){
node = skel_nodes.groupItems[i]
id = node.name
bounds = node.geometricBounds
centre = get_centre(bounds)
x = centre[0]
repo = ((x - min_left) / interval) + 1
reposition[id] = repo
}
out_file.open("w");
out_file.write(JSON.stringify(reposition));
out_file.close();