-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChange Comps BG.jsx
More file actions
71 lines (68 loc) · 1.66 KB
/
Change Comps BG.jsx
File metadata and controls
71 lines (68 loc) · 1.66 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
/**
* Mass change compositions background color
* through a simple UI.
*
* @author github.com/ilovedoumiao
* @version 1.0
*/
function changeCompBG(o, e, n) {
function r(e) {
e.bgColor = o
}
if (n)
for (var a = 1; a <= app.project.numItems; a++) {
var t = app.project.item(a);
t instanceof CompItem && r(t)
} else
for (var a = 0; a < e.length; a++) {
var l = e[a];
l instanceof CompItem && r(l)
}
}
function hexToRgb(o) {
var e = parseInt(o = o.replace("#", ""), 16);
return [(e >> 16 & 255) / 255, (e >> 8 & 255) / 255, (255 & e) / 255]
}
function showUI() {
var o = new Window("dialog", "Change Comp BG Color");
o.add("statictext", void 0, "BG Color (Hex value omit #):");
var e = o.add("edittext", void 0, "ffffff");
e.characters = 10;
var n = o.add("checkbox", void 0, "Apply to all comps in project");
n.value = !1, e.active = !0;
var r = o.add("group"),
a = r.add("button", void 0, "OK"),
t = r.add("button", void 0, "Cancel"),
l = {
hexColor: null,
applyToAll: !1
};
return a.onClick = function() {
var r = e.text,
a = n.value;
if (!/^([0-9A-F]{3}){1,2}$/i.test(r)) {
alert("Please enter a valid hex color value.");
return
}
l.hexColor = r, l.applyToAll = a, o.close()
}, t.onClick = function() {
o.close()
}, o.show(), l
}
function main() {
app.beginUndoGroup("Change Comp BG Color");
var o = app.project.selection,
e = showUI();
if (null === e.hexColor) {
app.endUndoGroup();
return
}
var n = hexToRgb(e.hexColor),
r = e.applyToAll;
if (0 === o.length && !r) {
alert("Select comp(s) in the Project window."), app.endUndoGroup();
return
}
changeCompBG(n, o, r), app.endUndoGroup()
}
main();