-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSolo Traveler.jsx
121 lines (97 loc) · 2.59 KB
/
Solo Traveler.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
/**
* Turns all guide layers into non-guide layers, in selected comps in project panel.
*
* Will recurse into precomps.
*
* Modifiers:
* - Hold SHIFT to only scan selected comps (ignoring precomps)
* - Hold CTRL to skip locked layers
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function soloTraveler() {
var SKIP_LOCKED_LAYERS = ScriptUI.environment.keyboardState.shiftKey;
var SKIP_PRECOMPS = ScriptUI.environment.keyboardState.ctrlKey;
var items = app.project.selection;
if (items.length === 0) {
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert("Open a comp!");
return;
}
items = [comp];
}
var totalUnguided = 0;
var ids = [];
app.beginUndoGroup("Solo Traveler");
try {
for (var ii = 0, il = items.length; ii < il; ii++) {
var item = items[ii];
var id = item.id;
// Ignore non-comps
if (!(item instanceof CompItem)) {
continue;
}
// Ignore items we've already touched
if (_itemWasTouched(id, ids)) {
continue;
}
totalUnguided += unguideLayers(item, ids).length;
ids.push(id);
}
alert("Unguided " + totalUnguided + " layers.");
} catch (e) {
alert(e, "Solo Traveler");
} finally {
app.endUndoGroup();
}
/**
* Check whether an item exists in an array
*
* @param {number} id Item ID
* @param {number[]} ids IDs to check
* @return {boolean} Whether ID exists
*/
function _itemWasTouched(id, ids) {
return ids.join("|").indexOf(id.toString()) > -1;
}
/**
* Counts comp keyframes
*
* @param {CompItem} comp Comp to count in
* @param {number[]} ids Parsed comp IDs
* @return {Layer[]} Unguided layers
*/
function unguideLayers(comp, ids) {
var guideLayers = [];
for (var ii = 1, il = comp.numLayers; ii <= il; ii++) {
var layer = comp.layer(ii);
var wasLocked = layer.locked;
if (SKIP_LOCKED_LAYERS && wasLocked) {
continue;
}
if (layer.source && layer.source instanceof CompItem) {
if (SKIP_PRECOMPS) {
continue;
}
var src = layer.source;
var id = src.id;
if (!_itemWasTouched(id, ids)) {
guideLayers = guideLayers.concat(unguideLayers(src, ids));
ids.push(id);
}
}
if (!(layer instanceof AVLayer)) {
continue;
}
if (!layer.guideLayer) {
continue;
}
layer.guideLayer = false;
layer.locked = wasLocked;
guideLayers.push(layer);
}
return guideLayers;
}
})();