-
Notifications
You must be signed in to change notification settings - Fork 56
/
importBoujouTracking.jsx
58 lines (46 loc) · 1.6 KB
/
importBoujouTracking.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
//Import Boujou 2d tracks to AE
//CC-BY Nik Ska, 2014
var parseBoujou = this;
parseBoujou.go = function(){
function createNull(comp, _name){
var newTrackNull = comp.layers.addNull();
newTrackNull.name = "Boujou Null_" + _name;
newTrackNull.threeDLayer = true;
newTrackNull.label = 10;
return newTrackNull;
}
var textFile = File.openDialog ("Choose a tracking data file","*.txt");
if (textFile != null) {
var textLines = [];
textFile.open("r");
while (!textFile.eof){
//reading file into lines
textLines.push(textFile.readln());
}
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
app.beginUndoGroup("Parse Boujou");
//regex to break line into segments
//null number / frame number / X / Y
var lineMatch = /(\S+(\s || $))/g;
var namelineMatch = /(\d+)/;
for(var t = 1; t<textLines.length; t++){
if(t>5){ //boujou file header is 5 lines long
var parsed = textLines[t].match(lineMatch);
var nullNum = textLines[t].match(nameMatch)[1];
//check for existing null
var curNull = activeComp.layer("Boujou Null_"+nullNum);
//create one if there is no null
if(!curNull) curNull = createNull(activeComp, nullNum);
if(parsed){
// $.writeln(textLines[t].match(XYmatch))
// $.writeln(Number(parsed[2]), ", ", Number(parsed[3]));;
curNull.property("ADBE Transform Group").property("ADBE Position").setValueAtTime(Number(parsed[1]-1)*activeComp.frameDuration, [Number(parsed[2]), Number(parsed[3]),0]);
}
}
}
}
app.endUndoGroup();
}
}
parseBoujou.go();