-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathApply Expression to Selection.jsx
86 lines (70 loc) · 1.97 KB
/
Apply Expression to Selection.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
/**
* Prompts user for an expression, and applies it to selected properties
*
* @author Zack Lovatt <[email protected]>
* @version 0.2.0
*/
(function applyExpressionToSelection() {
var DEFAULT_EXPRESSION = "loopIn() + loopOut() - value;";
_getUserExpression(DEFAULT_EXPRESSION);
/**
* Applies an expression to selected prop(s)
*
* @param {string} expression Expression to apply
*/
function applyExpression(expression) {
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert("Open a comp!");
return;
}
var props = comp.selectedProperties;
if (props.length === 0) {
alert("Select properties to apply expression to!");
return;
}
if (!expression || expression == "") {
alert("Enter an expression");
return;
}
app.beginUndoGroup("Apply Expression to Selected Properties");
try {
for (var ii = 0, il = props.length; ii < il; ii++) {
var prop = props[ii];
if (!prop.canSetExpression) {
continue;
}
prop.expression = expression;
}
} catch (e) {
alert(e);
} finally {
app.endUndoGroup();
}
}
function _getUserExpression(defaultExpression) {
var win = new Window("palette", "Apply Expression to Selection", undefined, {
resizeable: true
});
win.alignChildren = "fill";
win.add("statictext", undefined, "Expression to apply:");
var editText = win.add("edittext", undefined, defaultExpression, {
multiline: true
});
editText.characters = 50;
editText.size = [500, 200];
editText.alignment = "fill";
var btnOk = win.add("button", undefined, "Apply");
btnOk.onClick = function () {
var userExpression = editText.text;
if (userExpression == "") {
alert("No expression to apply!");
return;
}
win.close();
applyExpression(userExpression);
};
btnOk.alignment = "right";
win.show();
}
})();