-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptAllLayers_1.4.jsx
527 lines (434 loc) · 19.6 KB
/
OptAllLayers_1.4.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
{
script(this);
// gui function - all of this is has to be this way
function script(thisObj){
function buildUI(thisObj){
// check if panel or window
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "OptAllLayers", undefined, {resizeable:true});
// content of gui
myPanel.alignChildren = ['fill', 'fill'];
myPanel.minimumSize = [194,324];
// ----------------------- Container -----------------------
container = myPanel.add('group');
container.orientation = 'stack';
container.alignChildren = ['fill','fill'];
container.minimumSize = myPanel.minimumSize;
// ----------------------- Main -----------------------
mainres = "group{orientation:'column', alignment:['fill','fill'], alignChildren:['fill','fill'],\
panelComp: Panel{text:'Composition', orientation:'column', alignment:['fill','top'], alignChildren:['fill','fill'],\
compList: DropDownList{properties:{items:['']}},\
compTxt: StaticText{text:'All composition selected'},\
},\
panelMB: Panel{text:'Motionblur', orientation:'row',alignment:['fill','top'], alignChildren:['fill','fill'],\
MBact: RadioButton{text:' on'},\
MBdeact: RadioButton{text:' off'},\
MBdn: RadioButton{text:' ignore'},\
},\
panelCT: Panel{text:'Collapse Transformation', orientation:'row',alignment:['fill','top'], alignChildren:['fill','fill'],\
CTact: RadioButton{text:' on'},\
CTdeact: RadioButton{text:' off'},\
CTdn: RadioButton{text:' ignore'},\
},\
panelOpt: Panel{text:'Include', orientation:'column',alignment:['fill','top'], alignChildren:['fill','fill'],\
subcompCheck: Checkbox{text:' layers in pre-comps'},\
invisiblelayerCheck: Checkbox{text:' invisible layers'},\
},\
groupOne: Group{orientation:'row', alignment:['fill','fill'],\
startBtn: Button{text:'Go!', alignment:['fill', 'fill']},\
infoBtn: Button{text:'?', alignment:['right', 'fill'], maximumSize:[20,10000]},\
},\
}";
mainPanel = container.add(mainres);
// ----------------------- About -----------------------
aboutres = "group{orientation:'column', alignment:['fill','fill'], alignChildren:['fill','fill'],\
groupTxt: Group{orientation:'column', alignment:['fill','top'], minimumSize:[190,284],\
aboutHl: StaticText{text:'OptAllLayers 1.4'},\
aboutTxt: StaticText{properties:{multiline: true}, maximumSize: [190,284], text:'\\nActivate or deactivate motionblur and collapse transformation for all layers with one click.\\n\\n'},\
prefBtn: Button{text:'Change Defaults',alignment:['fill', 'fill']},\
blindTxt: StaticText{text:''},\
urlTxt: StaticText{minimumSize: [190,0], text:'Developed by:'},\
urlBtn: Button{text:'www.vogelmoritz.de',alignment:['fill', 'fill']},\
mailTxt: StaticText{minimumSize: [190,0], text:'Contact:'},\
mailBtn: Button{text:'[email protected]',alignment:['fill', 'fill']},\
},\
groupOne: Group{orientation:'column', alignment:['fill','fill'],\
backBtn: Button{text:'< back',alignment:['fill', 'fill']},\
},\
}";
aboutPanel = container.add(aboutres);
aboutPanel.hide();
// ----------------------- Prefs -----------------------
prefres = "group{orientation:'column', alignment:['fill','fill'], alignChildren:['fill','fill'],\
groupTxt: Group{orientation:'column', alignment:['fill','top'],\
prefTxt: StaticText{text: 'Select your default settings', alignment:['left','top']},\
},\
panelComp: Panel{text:'Composition', orientation:'column', alignment:['fill','top'], alignChildren:['fill','fill'],\
compList: DropDownList{properties:{items:['ALL', 'SELECTION']}},\
},\
panelMB: Panel{text:'Motionblur', orientation:'row',alignment:['fill','top'], alignChildren:['fill','fill'],\
MBact: RadioButton{text:' on'},\
MBdeact: RadioButton{text:' off'},\
MBdn: RadioButton{text:' ignore'},\
},\
panelCT: Panel{text:'Collapse Transformation', orientation:'row',alignment:['fill','top'], alignChildren:['fill','fill'],\
CTact: RadioButton{text:' on'},\
CTdeact: RadioButton{text:' off'},\
CTdn: RadioButton{text:' ignore'},\
},\
panelOpt: Panel{text:'Include', orientation:'column',alignment:['fill','top'], alignChildren:['fill','fill'],\
subcompCheck: Checkbox{text:' layers in pre-comps'},\
invisiblelayerCheck: Checkbox{text:' invisible layers'},\
},\
groupOne: Group{orientation:'row', alignment:['fill','fill'],\
backBtn: Button{text:'< back', alignment:['fill', 'fill']},\
saveBtn: Button{text:'save', alignment:['fill', 'fill']},\
},\
}";
prefPanel = container.add(prefres);
prefPanel.panelComp.compList.selection = 0;
prefPanel.panelMB.MBdn.value = true;
prefPanel.panelCT.CTdn.value = true;
prefPanel.hide();
// ----------------------- Pop Up Window -----------------------
var PopupBox = new Window("palette", "processing...", undefined, {resizeable:false, closeButton:false});
PopupBox.alignChildren = ['fill', 'fill'];
processres = "group{orientation:'column', alignment:['fill','fill'], alignChildren:['fill','fill'],\
groupTxt: Group{orientation:'column', alignment:['fill','fill'], size:[400,40],\
infoBoxTxtupper: StaticText{text: 'processing layer:', alignment:['fill','fill']},\
infoBoxTxt: StaticText{text: '', alignment:['fill','fill']},\
},\
}";
processBox = PopupBox.add(processres);
// panel sizing and resizing
myPanel.layout.layout(true);
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function(){
this.layout.resize();
// dd item size bug fix
prefPanel.panelComp.compList.itemSize = mainPanel.panelComp.compList.itemSize = [mainPanel.panelComp.compList.size[0]-27,mainPanel.panelComp.compList.size[1]];
};
// grap all comps and add them to dropdownlist
listallcomps();
// set defaults
var myFileName = "OptAllLayersPrefs.txt";
var myFilePath = File($.fileName).path + "/" + myFileName;
if (File(myFilePath).exists){
myFile = File(myFilePath);
myFile.open("r");
eval(myFile.read());
myFile.close();
} else {
mainPanel.panelComp.compList.selection = 0;
mainPanel.panelMB.MBact.value = false;
mainPanel.panelMB.MBdeact.value = false;
mainPanel.panelMB.MBdn.value = true;
mainPanel.panelCT.CTact.value = false;
mainPanel.panelCT.CTdeact.value = false;
mainPanel.panelCT.CTdn.value = true;
mainPanel.panelOpt.subcompCheck.value = false;
mainPanel.panelOpt.invisiblelayerCheck.value = false;
}
// <-- END OF INTERFACE
// -----------------------------------------------------------------------------------------------------
// --------------------------------------------- EVENTS --------------------------------------------
// -----------------------------------------------------------------------------------------------------
// ---------------------- REFRESH TEXT AND COMPARRAY ----------------------
mainPanel.addEventListener("mouseover", UpdateTextCreateProcessComp);
// --------------------------- RESET STATIC TEXT --------------------------
//mainPanel.addEventListener("mouseout", myTimeout);
// ----------------------- REFRESH COMPOSITION LIST -----------------------
mainPanel.panelComp.addEventListener("mouseover", listallcomps);
// ----------------------- REFRESH PREFTXT -----------------------
prefPanel.addEventListener("mouseover", function(){prefPanel.groupTxt.prefTxt.text = "Select your default settings";});
// -----------------------------------------------------------------------------------------------------
// ---------------------------------------------- BUTTONS ----------------------------------------------
// -----------------------------------------------------------------------------------------------------
// ----------------------- GO -----------------------
mainPanel.groupOne.startBtn.onClick = function(){
// change button text to show, that the script is running
mainPanel.groupOne.startBtn.text = "processing...";
if (myPanel instanceof Window){
myPanel.update();
} else {
PopupBox.center();
PopupBox.show();
}
// read out settings: mb, ct, pc, ll
// --------- MOTIONBLUR ---------
if (mainPanel.panelMB.MBact.value){
mb = true;
} else if (mainPanel.panelMB.MBdeact.value){
mb = false;
} else if (mainPanel.panelMB.MBdn.value){
mb = null;
}
// --------- COLLAPSE TRANSFFORMATION ---------
if (mainPanel.panelCT.CTact.value){
ct = true;
} else if (mainPanel.panelCT.CTdeact.value){
ct = false;
} else if (mainPanel.panelCT.CTdn.value){
ct = null;
}
// --------- PRECOMPS ---------
pc = mainPanel.panelOpt.subcompCheck.value;
// --------- INVISIBLE LAYERS ---------
il = mainPanel.panelOpt.invisiblelayerCheck.value;
// DO THE MAGIC
app.beginUndoGroup('OptAllLayers');
exec(processComp);
app.endUndoGroup();
// reset button text to normal state
mainPanel.groupOne.startBtn.text = "Go!";
mainPanel.panelComp.compTxt.text = "done";
PopupBox.hide();
}
// ----------------------- INFO -----------------------
mainPanel.groupOne.infoBtn.onClick = function(){
mainPanel.hide();
aboutPanel.show();
prefPanel.hide();
}
// ----------------------- BACK -----------------------
aboutPanel.groupOne.backBtn.onClick = function(){
mainPanel.show();
aboutPanel.hide();
prefPanel.hide();
}
// ----------------------- URL -----------------------
aboutPanel.groupTxt.urlBtn.onClick = function(){
url = "";
cmd = null;
if ($.os.indexOf("Win") != -1){
cmd = "cmd.exe /k start " + url ;
} else {
cmd = "open \"" + url + "\"";
}
if (cmd != null){
system.callSystem(cmd);
} else {
alert ("No browser found.")
}
}
// ----------------------- MAIL -----------------------
aboutPanel.groupTxt.mailBtn.onClick = function(){
mail = "";
cmd = null;
if ($.os.indexOf("Win") != -1){
cmd = "cmd.exe /k" + " start mailto:" + mail + "?subject=OptAllLayers"
} else {
cmd = "open \"" + url + "\"";
}
if (cmd != null){
system.callSystem(cmd);
} else {
alert ("No e-mail client found.")
}
}
// ----------------------- SETTINGS -----------------------
aboutPanel.groupTxt.prefBtn.onClick = function(){
mainPanel.hide();
aboutPanel.hide();
prefPanel.show();
}
// ----------------------- SETTINGS BACK -----------------------
prefPanel.groupOne.backBtn.onClick = function(){
mainPanel.hide();
aboutPanel.show();
prefPanel.hide();
}
// ----------------------- SETTINGS SAVE -----------------------
prefPanel.groupOne.saveBtn.onClick = function(){
prefdd = String(prefPanel.panelComp.compList.selection.index);
prefmbact = String(prefPanel.panelMB.MBact.value);
prefmbdeact = String(prefPanel.panelMB.MBdeact.value);
prefmbdn = String(prefPanel.panelMB.MBdn.value);
prefctact = String(prefPanel.panelCT.CTact.value);
prefctdeact = String(prefPanel.panelCT.CTdeact.value);
prefctdn = String(prefPanel.panelCT.CTdn.value);
prefpc = String(prefPanel.panelOpt.subcompCheck.value);
prefil = String(prefPanel.panelOpt.invisiblelayerCheck.value);
var myMessage = "mainPanel.panelComp.compList.selection = " + prefdd + ";\nmainPanel.panelMB.MBact.value = " + prefmbact + ";\nmainPanel.panelMB.MBdeact.value = " + prefmbdeact + ";\nmainPanel.panelMB.MBdn.value = " + prefmbdn + ";\nmainPanel.panelCT.CTact.value = " + prefctact + ";\nmainPanel.panelCT.CTdeact.value = " + prefctdeact + ";\nmainPanel.panelCT.CTdn.value = " + prefctdn + ";\nmainPanel.panelOpt.subcompCheck.value = " + prefpc + ";\nmainPanel.panelOpt.invisiblelayerCheck.value = " + prefil + ";";
myFile = new File(myFilePath);
myFile.open("w");
myFile.write(myMessage);
myFile.close();
prefPanel.groupTxt.prefTxt.text = "Settings saved!";
myFile.open("r");
eval(myFile.read());
myFile.close();
}
// -----------------------------------------------------------------------------------------------------
// --------------------------------------------- FUNCTIONS ---------------------------------------------
// -----------------------------------------------------------------------------------------------------
// ------------------- UpdateTextCreateProcessComp -------------------
function UpdateTextCreateProcessComp(){
// reset array so we always start fresh and clean
processComp = [];
// read out settings: comp
// produce processComp array, which includes all comps which need to be processed
// --------- ALL ---------
if (mainPanel.panelComp.compList.selection == 0){
for (i = 1; i <= app.project.numItems; i++){
if (app.project.items[i] instanceof CompItem){
processComp.push(app.project.items[i]);
mainPanel.panelComp.compTxt.text = "All composition selected";
}
}
}
// --------- SELECTION ---------
if (mainPanel.panelComp.compList.selection == 1){
// case 1: project panel no selection, or project panel selected with only one item, or comppanel selected
if ((app.project.selection.length >= 0) && (app.project.activeItem != null) && (app.project.activeItem instanceof CompItem)){
processComp = [app.project.activeItem];
mainPanel.panelComp.compTxt.text = processComp[0].name + " selected";
} else if ((app.project.selection.length == 0) && (app.project.activeItem == null)){
mainPanel.panelComp.compTxt.text = "No composition will be processed.";
}
// case 2: project panel one or more selection
// project panel selected with more than one item
if ((app.project.selection.length > 0) && (app.project.activeItem == null)){
// filter compItems from selection and push them to processComp
for (i = 0; i <= app.project.selection.length; i++){
if (app.project.selection[i] instanceof CompItem){
processComp.push(app.project.selection[i]);
mainPanel.panelComp.compTxt.text = processComp.length + " compositions selected";
}
}
}
// if only folders and stuff is selected
if (processComp.length == 0){
mainPanel.panelComp.compTxt.text = "No composition selected";
}
}
// --------- SPECIFIED ---------
if (mainPanel.panelComp.compList.selection > 1){
// use the index from the dd to refer to the array - aka to the actual [object item]. -3 because the dd has already some entries
processComp = [compArr[mainPanel.panelComp.compList.selection.index - 3]];
mainPanel.panelComp.compTxt.text = processComp[0].name + " selected";
}
// <- end of dropdown
return processComp;
}
// ------------------- TIMEOUT -------------------
function myTimeout (){
app.setTimeout(resetText,5000);
}
// ------------------- RESETTEXT -------------------
function resetText (){
mainPanel.panelComp.compTxt.text = "";
}
// ------------------- LISTALLCOMPS -------------------
function listallcomps (){
// grap listitemindex to set this one as default later
itemSel = String(mainPanel.panelComp.compList.selection);
// reset array and dd
compArr = [];
mainPanel.panelComp.compList.removeAll();
// re-add prototype entries
mainPanel.panelComp.compList.add('item','ALL');
mainPanel.panelComp.compList.add('item','SELECTION');
mainPanel.panelComp.compList.add('separator','-');
// 3 entries do already exist, we start counting from 0
j = 2;
// add all other entries
for (i = 1; i <= app.project.numItems; i++){
if (app.project.items[i] instanceof CompItem){
// push all matches as [object item] to the array
compArr.push(app.project.items[i]);
// add all names of [object item] to the dropdown
mainPanel.panelComp.compList.add('item',app.project.items[i].name);
// everytime the if kicks in, j increases
j++;
// if previous selected item is just added item, this one gets selection
if (itemSel == app.project.items[i].name){
mainPanel.panelComp.compList.selection = j;
}
}
}
// if one of the statics entries where selected, they get restored
if (itemSel == "ALL" || itemSel == null){
mainPanel.panelComp.compList.selection = 0;
} else if (itemSel == "SELECTION"){
mainPanel.panelComp.compList.selection = 1;
}
return compArr;
}
// ------------------- EXEC (DO THE MAGIC FUNTION) -------------------
function exec (processComp){
// compositions loop
for (var i = 0; i < processComp.length; i++){
var comp = processComp[i];
var layers = comp.layers;
var layers_counter = comp.layers.length;
var relock = false;
// activate motionblur switch in compviewer
if (mb != null){
comp.motionBlur = mb;
}
// layers loop
for (var j = 1; j <= layers_counter; j++){
layer = layers[j];
visible = layers[j].enabled; // layer is visible
locked = layers[j].locked; // layer is locked
if (locked){
layer.locked = false;
relock = true;
}
//-------------- OPTION: INCLUDE INVISIBLE LAYERS --------------
// case 1: layer is visible
if (visible){
execOptions();
// case 2: layer is not visible and option is not checked
} else if (visible == false && il == false){
continue;
// case 3: layer is not visible and option is checked
} else if (visible == false && il){
execOptions();
}
// -------------- OPTION: INCLUDE PRECOMPS --------------
if (pc && layer.source instanceof CompItem){
exec([layer.source]);
}
if (relock){
layer.locked = true;
}
}
}
}
// ------------------- execOptions -------------------
function execOptions (){
// do motion blur
if (mb != null){
mainPanel.panelComp.compTxt.text = "processing layer: " + layer.name;
processBox.groupTxt.infoBoxTxt.text = layer.name;
if (myPanel instanceof Window){
myPanel.update();
} else {
PopupBox.update();
}
layer.motionBlur = mb;
}
// do coltrans
if ((ct != null) && (layer.canSetCollapseTransformation)){
mainPanel.panelComp.compTxt.text = "processing layer: " + layer.name;
processBox.groupTxt.infoBoxTxt.text = layer.name;
if (myPanel instanceof Window){
myPanel.update();
} else {
PopupBox.update();
}
layer.collapseTransformation = ct;
}
}
// <-- end of main function
return myPanel;
}
// floating window
var myScriptPal = buildUI(thisObj);
if ((myScriptPal != null) && (myScriptPal instanceof Window)){
myScriptPal.center();
myScriptPal.show();
}
}
}