-
Notifications
You must be signed in to change notification settings - Fork 0
/
FadeIt v3.jsx
executable file
·120 lines (102 loc) · 4.91 KB
/
FadeIt v3.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
// FadeIt v3 by Viv Chawda
// v3: 11-2019
// Twitter: @vivchawda
//
// Inspired from kd_AutoFade v1.3 by @takumi_kashima
// This script automatically adds fadeIn and fadeOut expressions to selected layers.
// Select option "M" to add fadeIn & fadeOut at layer markers 1 & 2 instead (ctrl+8)
function fadit_main(thisObj){
function fadit_createPalette(thisObj) {
palette= (thisObj instanceof Panel) ? thisObj : new Window("palette", "FadeIt v3", undefined, {resizeable: true});
palette.alignChildren = 'left';
with(palette){
palette.H = add('group');
palette.H.orientation = 'row';
with(palette.H){
palette.H.sText = add('statictext', undefined, 'T(s):');
palette.H.ftime = add('edittext', undefined, '0.5');
palette.H.ftime.preferredSize = [40,20];
palette.H.inout = add('dropdownlist',[10,10,100,30],['In and Out', 'In only', 'Out only']);
palette.H.inout.selection = 0;
palette.H.easing = add('checkbox', undefined, 'E');
palette.H.easing.value = true;
palette.H.marker = add('checkbox', undefined, 'M');
}
palette.F = add('group');
palette.F.orientation = 'row';
palette.F.alignChildren = 'fill';
with(palette.F){
palette.F.Btn = add('button', undefined, 'Apply');
palette.F.Btn2 = add('button', undefined, 'Remove');
}
palette.F.Btn.onClick = applyExpression;
palette.F.Btn2.onClick = removeExpression;
};
return palette;
}
var fadit_palette = fadit_createPalette(thisObj);
if (fadit_palette instanceof Window){
fadit_palette.show();
}else{
fadit_palette.layout.layout(true);
}
function removeExpression() {
var curComp = app.project.activeItem;
for (var layerId = 0; layerId < curComp.selectedLayers.length; layerId++){
var layer = curComp.selectedLayers[layerId];
layer('opacity').expression='';
}
}
function applyExpression() {
var ExpText = '';
var curComp = app.project.activeItem;
for (var layerId = 0; layerId < curComp.selectedLayers.length; layerId++){
var layer = curComp.selectedLayers[layerId];
ExpText = makeExpression(palette.H.ftime.text, palette.H.inout.selection.text,palette.H.marker.value)
layer('opacity').expression=ExpText;
}
}
function makeExpression(ftime, ioc, mar){
exp='';
func1 = 'easeIn';
func2 = 'easeOut';
from = 0;
to = 100;
if(mar){
if(ioc == 'In and Out'){
exp = 'fadeIn = easeIn(time, marker.key(1).time, marker.key(1).time + '+ftime+', 0, 100)\nfadeOut = easeOut(time, marker.key(2).time - '+ftime+', marker.key(2).time, 0, 100)\nfadeIn - fadeOut';
}else if(ioc == 'In only'){
exp = 'easeIn(time, marker.key(1).time, marker.key(1).time + '+ftime+', 0, 100)';
}else if(ioc == 'Out only'){
exp = 'easeOut(time, marker.key(2).time - '+ftime+', marker.key(2).time, 100, 0)';
}
}else{
if(ioc == 'In and Out'){
exp = 'fTime = '+ftime+';\r'+
'if(time <= thisLayer.inPoint+fTime){\r'+
' '+func1+'(time,thisLayer.inPoint,thisLayer.inPoint+fTime,'+from+','+to+');\r' +
'}else if(time >= thisLayer.outPoint-fTime){\r' +
' '+func2+'(time,thisLayer.outPoint-fTime,thisLayer.outPoint,'+to+','+from+');\r' +
'}else{\r' +
' '+to+';\r'+
'}';
}else if(ioc == 'In only'){
exp = 'fTime = '+ftime+';\r'+
'if(time <= thisLayer.inPoint+fTime){\r'+
' '+func1+'(time,thisLayer.inPoint,thisLayer.inPoint+fTime,'+from+','+to+');\r' +
'}else{\r' +
' '+to+';\r'+
'}';
}else if(ioc == 'Out only'){
exp = 'fTime = '+ftime+';\r'+
'if(time >= thisLayer.outPoint-fTime){\r' +
' '+func2+'(time,thisLayer.outPoint-fTime,thisLayer.outPoint,'+to+','+from+');\r' +
'}else{\r' +
' '+to+';\r'+
'}';
}
}
return exp;
}
}
fadit_main(this);