-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInjectExpression.jsx
More file actions
220 lines (157 loc) · 9.59 KB
/
InjectExpression.jsx
File metadata and controls
220 lines (157 loc) · 9.59 KB
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
{
function script(thisObj){
function buildUI(thisObj){
// --------------------------------------------------------------------------------------------
// ---------------------------------------- METAINFOS -------------------------------
// --------------------------------------------------------------------------------------------
appname = "InjectExpression";
version = "1.0";
date = "August 2017";
desription = "Reads out and pasts an Expression into selected layer properties. Before pasting, Expressions can be created or edited."
copyright = "Martin Ritter @ Vogel & Moritz GbR";
// --------------------------------------------------------------------------------------------
// ---------------------------------------- INTERFACE --------------------------------
// --------------------------------------------------------------------------------------------
// panel or window?
var IEPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", appname, undefined, {resizeable:true});
// ----------------------- Container -----------------------
IEPanel.alignChildren = ['fill', 'fill'];
IEPanel.minimumSize = [200,100];
IEPanel.add('group');
IEPanel.orientation = 'stack';
// -------------------------- Main -------------------------
mainres = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill','fill'], minimumSize:[200,100],\
gr_et: Group{orientation: 'stack', alignment:['fill', 'fill'], alignChildren:['fill','fill'],\
st: StaticText{properties:{multiline: true}, alignment:['fill','fill']},\
et: EditText{properties:{multiline: true}}\
},\
gr_btn: Group{orientation:'row',alignment:['fill', 'bottom'], alignChildren:['fill','fill'],\
btn_ro: Button{text:'Read out', maximumSize:[10000,20]},\
btn_ie: Button{text:'Inject!', maximumSize:[10000,20]},\
btn_about: Button{text:'?', alignment:['right', 'fill'], maximumSize:[15,20]}\
}\
}";
IEMainPanel = IEPanel.add(mainres);
// ------------------- Init UI: Colors and Presets ---------------------
var btn_ro_bg = [20,61,102,100];
var btn_ie_bg = [102,0,19,100];
var btn_txt = [185,185,185,255];
var dim = 100;
colorObj(IEMainPanel.gr_btn.btn_ro, btn_ro_bg, btn_txt);
colorObj(IEMainPanel.gr_btn.btn_ie, btn_ie_bg, btn_txt);
IEMainPanel.gr_et.st.text = st_initText;
IEMainPanel.gr_et.et.hide();
// ------------------- Texts ---------------------
st_initText = "Select a property with an expression and click on Read out or move mouse to this text to enter an new expression";
// -------------------------- Resizing ----------------------
IEPanel.layout.layout(true);
IEPanel.layout.resize();
IEPanel.onResizing = IEPanel.onResize = function(){
this.layout.resize();
};
// --------------------------------------------------------------------------------------------
// ----------------------------------------- EVENTS ------------------------------------
// --------------------------------------------------------------------------------------------
IEMainPanel.gr_btn.btn_ro.addEventListener("mouseover", btn_ro_mo);
IEMainPanel.gr_btn.btn_ie.addEventListener("mouseover", btn_ie_mo);
IEMainPanel.gr_btn.btn_ro.addEventListener("mouseout", btn_ro_mout);
IEMainPanel.gr_btn.btn_ie.addEventListener("mouseout", btn_ie_mout);
IEMainPanel.gr_et.addEventListener("mouseover", activeEditMode);
IEMainPanel.gr_et.et.addEventListener("mouseout", deactiveEditMode);
// --------------------------------------------------------------------------------------------
// ----------------------------------------- BUTTONS ----------------------------------
// --------------------------------------------------------------------------------------------
// -------------------------- Read Out ----------------------
IEMainPanel.gr_btn.btn_ro.onClick = function(){
readout();
}
// -------------------------- Inject ----------------------
IEMainPanel.gr_btn.btn_ie.onClick = function(){
app.beginUndoGroup('InjectExpression');
inject();
app.endUndoGroup();
}
// --------------------------------------------------------------------------------------------
// ---------------------------------------- FUNCTIONS --------------------------------
// --------------------------------------------------------------------------------------------
// -------------------------- Color Buttons ----------------------
function colorObj(myobj,bgcolor,txtcolor){
bgcolor = rgba_to_aecmodel(bgcolor);
txtcolor = rgba_to_aecmodel(txtcolor);
myobj.pen = myobj.graphics.newPen(myobj.graphics.PenType.SOLID_COLOR, txtcolor, 1);
myobj.brush = myobj.graphics.newBrush(myobj.graphics.BrushType.SOLID_COLOR, bgcolor);
myobj.onDraw = function(){
with(this){
graphics.drawOSControl();
graphics.rectPath(0,0,size[0], size[1]);
graphics.fillPath(brush);
// center text
stringsize = graphics.measureString(text,graphics.font, size[0]);
x = (size[0]-stringsize[0])/2;
y = (size[1]-stringsize[1])/2;
graphics.drawString(text,myobj.pen,x,y,graphics.font);
}
}
}
// -------------------------- Convert 0-255 to 0-1 ----------------------
function rgba_to_aecmodel(rgba){
ae_r = rgba[0]/255;
ae_g = rgba[1]/255;
ae_b = rgba[2]/255;
ae_a = rgba[3]/255;
return [ae_r, ae_g, ae_b, ae_a];
}
// --------------------- Button Mouseover and Mouseout -------------------
function btn_ro_mo(){
btn_ro_bg[3]=255;
colorObj(IEMainPanel.gr_btn.btn_ro, btn_ro_bg, btn_txt);
}
function btn_ro_mout(){
btn_ro_bg[3]=dim;
colorObj(IEMainPanel.gr_btn.btn_ro, btn_ro_bg, btn_txt);
}
function btn_ie_mo(){
btn_ie_bg[3]=255;
colorObj(IEMainPanel.gr_btn.btn_ie, btn_ie_bg, btn_txt);
}
function btn_ie_mout(){
btn_ie_bg[3]=dim;
colorObj(IEMainPanel.gr_btn.btn_ie, btn_ie_bg, btn_txt);
}
// -------------------------- Activate EditMode ------------------------
function activeEditMode(){
IEMainPanel.gr_et.et.show();
}
// -------------------------- Deactivate EditMode ----------------------
function deactiveEditMode(){
if (IEMainPanel.gr_et.et.text != 0){
IEMainPanel.gr_et.st.text = IEMainPanel.gr_et.et.text;
} else {
IEMainPanel.gr_et.st.text = st_initText;
}
IEMainPanel.gr_et.et.hide();
}
// -------------------------- Readout Expression ----------------------
function readout(){
ro_expr = app.project.activeItem.selectedLayers[0].selectedProperties[0].expression;
IEMainPanel.gr_et.st.text = IEMainPanel.gr_et.et.text = ro_expr;
}
// -------------------------- Inject Expression ----------------------
function inject(){
in_expr = IEMainPanel.gr_et.et.text;
selection = app.project.activeItem.selectedProperties;
for(i = 0; i<= selection.length; i++){
selection[i].expression = in_expr;
}
}
// <-- END OF FUNCTIONS
return IEPanel;
}
var myScriptPal = buildUI(thisObj);
if ((myScriptPal != null) && (myScriptPal instanceof Window)){
myScriptPal.center();
myScriptPal.show();
}
}
script(this);
}