-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathGet Property Value.jsx
133 lines (111 loc) · 2.99 KB
/
Get Property Value.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
/**
* Gets value of current property at current time.
*
* @author Zack Lovatt <[email protected]>
* @version 0.2.0
*/
(function getPropertyValue(thisObj) {
/**
* Draws UI
*/
function createUI() {
var win =
thisObj instanceof Panel
? thisObj
: new Window("palette", "Get Property Value", undefined, {
resizeable: true
});
win.add("statictext", undefined, "Current Property Value:");
win.alignChildren = ["left", "top"];
win.minimumSize = [50, 80];
win.et = win.add("edittext", undefined, "", {
multiline: true
});
win.et.minimumSize = [50, 30];
win.et.alignment = ["fill", "fill"];
var grpBtns = win.add("group");
grpBtns.orientation = "row";
grpBtns.alignChildren = ["left", "top"];
var btnUpdate = grpBtns.add("button", undefined, "Update");
btnUpdate.onClick = function () {
try {
win.et.text = getValue();
} catch (e) {
alert(e, "Get Property Value Error");
return;
}
};
var btnCopy = grpBtns.add(
"button",
undefined,
"Copy to Clipboard (wait 2s)"
);
btnCopy.onClick = function () {
copyToClipboard(win.et.text);
};
win.layout.layout();
win.et.active = true;
win.onResizing = win.onResize = function () {
this.layout.resize();
};
return win;
}
/**
* Copies text to clipboard (may not work in all cases!)
*
* @param {string} text Text to copy
*/
function copyToClipboard(text) {
var command = 'echo "' + text + '" | pbcopy';
if ($.os.indexOf("Windows") > -1) {
command = 'cmd.exe /c cmd.exe /c "echo ' + text + ' | clip"';
}
system.callSystem(command);
}
/**
* Gets value of currently selected property
*
* @returns {string} Text value of property
*/
function getValue() {
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
throw "Open a comp!";
}
var properties = comp.selectedProperties;
if (properties.length === 0 || properties.length > 2) {
throw "Select only 1 property!";
}
var last = properties.pop();
var lastName = last.name.toString();
if (
last.propertyValueType === PropertyValueType.NO_VALUE ||
last.propertyValueType === PropertyValueType.CUSTOM_VALUE ||
last.propertyValueType === PropertyValueType.MARKER ||
last.propertyValueType === PropertyValueType.SHAPE
) {
throw "Can't read property '" + lastName.toString() + "'";
}
var value = last.valueAtTime(comp.time, false);
return value.toString();
}
var gpvWindow = createUI();
if (!gpvWindow) {
return;
}
if (gpvWindow instanceof Window) {
var initialValue;
// run right away
try {
initialValue = getValue();
} catch (e) {
alert(e, "Get Property Value Error");
return;
}
gpvWindow.et.text = initialValue;
gpvWindow.show();
} else {
// launch panel
gpvWindow.layout.layout(true);
}
})(this);