forked from dokluch/After-Effects-scripting-snippets
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHUD_placer.jsx
203 lines (165 loc) · 7.78 KB
/
HUD_placer.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//HUD text placer
//Written by Nik Ska
//Excusively for George Hurdubae
//http://aescripts.com/authors/nik-ska/
var textSetter = this;
if($.os.substr(0,7).toLowerCase() == "windows"){var prefix = "explorer "};
else{var prefix = "open ";}
textSetter.link1 = prefix + "http://videohive.net/item/animated-hud-alphabet/5080801";
textSetter.link2 = prefix + "http://aescripts.com/authors/m-p/nik-ska/";
textSetter.link3 = prefix + "mailto:[email protected]";
textSetter.letterMap = ['0','1','2','3','4','5','6','7','8','9',"'",'-','!','"','#','$','%','&','(',')',',','.','/',':',';','?','@','[',"\\",']','€','+','<','=','>','A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','Q','q','R','r','S','s','space','T','t','U','u','V','v','W','w','X','x','Y','y','Z','z'];
textSetter.setTextLayers = function(thisObj, _text){
var activeComp = app.project.activeItem;
if(activeComp != null && (activeComp instanceof CompItem)) {
if(_text){
var lettersFolder = thisObj.getLettersFolder();
if(lettersFolder){
app.beginUndoGroup("Placing HUD text");
thisObj.posNull = activeComp.layers.addNull();
thisObj.posNull.name = "Text Controller_"+String(thisObj.posNulls);
thisObj.posNull.property("Marker").setValueAtTime(0, new MarkerValue("Adjust " + '"'+ _text +'"' + " size, tracking and position"));
var spacing = thisObj.posNull("Effects").addProperty("ADBE Slider Control");
spacing.name = "Tracking";
spacing.value = 0;
var textSize = thisObj.posNull("Effects").addProperty("ADBE Slider Control");
textSize.name = "Size";
thisObj.posNull.effect(2).slider.setValue(100);
thisObj.posNulls++;
thisObj.posNull.label = (posNulls)%4+11;
thisObj.posNull.transform.position.setValue([-1104,584,0]);
for(var i = 0; i<_text.length; i++){
if(_text[i]!= ' '){
var letterToPlace = thisObj.getLetter(_text[i], lettersFolder, thisObj.letterMap);
if(letterToPlace) var lettr = activeComp.layers.add(letterToPlace);
}
else{
var lettr = activeComp.layers.add(thisObj.getLetter("space", lettersFolder, thisObj.letterMap));
}
if(lettr){
lettr.position.setValue([0,0,0]);
lettr.position.expression = "cntrl = thisComp.layer("+"'"+thisObj.posNull.name+"'"+");\ncntrl.toComp(cntrl.transform.anchorPoint) - (cntrl.index-index)*(7*cntrl.effect(2)(1)+cntrl.effect(1)(1))+value";
lettr.scale.expression = "value*thisComp.layer("+"'"+thisObj.posNull.name+"'"+").effect(2)(1)/100";
lettr.threeDLayer = true;
lettr.collapseTransformation = true;
lettr.label = thisObj.posNull.label;
if(i>0) lettr.moveAfter(activeComp.layers[i+1])
}
}
if(activeComp.layers[1]!=thisObj.posNull){
thisObj.posNull.moveBefore(activeComp.layers[1])
}
for(var k = 1; k<=activeComp.layers.length; k++){
var l = activeComp.layers[k];
if((l.name == "Master Controller") || (l.name == "Camera Controller") || (l.name == "Camera")){
l.moveBefore(activeComp.layers[1]);
}
}
app.endUndoGroup();
}
}
}
}
textSetter.buildGUI = function(thisObj){
thisObj.posNulls = thisObj.findPreviousInstances();
thisObj.w = (thisObj instanceof Panel) ? thisObj : new Window("palette", thisObj.scriptTitle, undefined, {resizeable:false});
thisObj.w.alignChildren = ["left", "top"];
//thisObj.w.setBG([0,.03,.03]);
thisObj.w.minimumSize = "width: 180, height: 110";
thisObj.w.maximumSize = "width:180, height: 110";
thisObj.w.add("staticText", undefined, "HUD text placer");
var textSet = thisObj.w.add("editText", undefined, "Write text and hit Enter");
textSet.size = [150,20];
var lineTwo = thisObj.w.add("group{orientation:'row'}");
lineTwo.size = "width: 155, height: 25"
var aboutBttn = lineTwo.add("button",undefined, "?");//.setFG([1,1,1]);
aboutBttn.alignment = ['right', 'top'];
aboutBttn.size = [20,20];
textSet.onEnterKey = function(){
setTextLayers(thisObj, textSet.text);
}
aboutBttn.onClick = function(){
thisObj.abt = new Window("palette", "About the script",undefined, {resizeable:false});//.setBG([0,.03,.03]);
thisObj.abt.alignChildren = ["left", "top"];
var abtPanel = thisObj.abt.add("panel{text: '', justify: 'center', alignment:['fill','top'], properties:{borderStyle: 'black'}}");
abtPanel.margins = 10;
abtPanel.alignChildren = ['left', 'top'];
abtPanel.add("staticText", undefined, "Script for the HUD Alphabet by IronykDesign");//.setFG([1,1,1]);
abtPanel.add("staticText", undefined, "http://videohive.net/item/animated-hud-alphabet/5080801").setFG([1, 0.58, 0.0]).addEventListener("mouseup", function(k){
if(k.button == 0){
system.callSystem(thisObj.link1)
}
});
abtPanel.add("staticText", undefined, "");
abtPanel.add("staticText", undefined, "Code by Nik Ska");
abtPanel.add("staticText", undefined, "http://aescripts.com/authors/m-p/nik-ska/").setFG([1, 0.58, 0.0]).addEventListener("mouseup", function(k){
if(k.button == 0){
system.callSystem(thisObj.link2);
}
});
abtPanel.add("staticText", undefined, "[email protected]").setFG([1, 0.58, 0.0]).addEventListener("mouseup", function(k){
if(k.button == 0){
system.callSystem(thisObj.link3);
}
});
thisObj.abt.center();
thisObj.abt.show();
}
if (thisObj.w instanceof Window){
thisObj.w.center();
thisObj.w.show();
}
else thisObj.w.layout.layout(true);
}
textSetter.getLetter = function(_name, _folder, _map){
function find(n, m){
for(var i = 0; i<m.length; i++){
if(m[i] == n) return i
}
return -1
}
var letterNumber = find(_name, _map);
if(letterNumber>=0){
return _folder.item(letterNumber+1)
}
else return null
}
textSetter.getLettersFolder = function(){
for(var i = 1; i<= app.project.numItems; i++){
if(app.project.item(i).name == "2. Letters"){
return app.project.item(i);
}
}
return null
}
textSetter.findPreviousInstances = function(){
var activeComp = app.project.activeItem;
var rx = /(Text Controller_)(\d)/;
if(activeComp){
var init = 1;
var tmp = 1;
for(var k = 1; k<=activeComp.layers.length; k++){
var match = activeComp.layers[k].name.match(rx);
if(match){
if(Number(match[2])>init) init = Number(match[2]);
}
if(init>tmp) tmp = init;
else if(init == tmp) tmp ++;
}
}
return tmp;
}
Object.prototype.setBG = function (colorArray) {
if (typeof colorArray != 'undefined' && colorArray.length >=3) {
this.graphics.backgroundColor = this.graphics.newBrush(this.graphics.BrushType.SOLID_COLOR, colorArray);
}
return this;
}
Object.prototype.setFG = function(colorArray) {
if (typeof colorArray != 'undefined' && colorArray.length >=3) {
this.graphics.foregroundColor = this.graphics.newPen(this.graphics.PenType.SOLID_COLOR, colorArray, 1);
}
return this;
}
textSetter.buildGUI(textSetter)