-
Notifications
You must be signed in to change notification settings - Fork 22
/
Delete Keys at Time.jsx
85 lines (73 loc) · 2.05 KB
/
Delete Keys at Time.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
/**
* Delete all keys at current time.
*
* @author Zack Lovatt <[email protected]>
* @version 0.2.2
*/
(function deleteKeysAtTime() {
/**
* Deletes keys at given time in a comp
*
* @param {CompItem} comp Comp to delete keys in
*/
function deleteKeysAtTime(comp) {
var userLayers = [];
var ii;
if (comp.selectedLayers.length !== 0) {
for (ii = 0; ii < comp.selectedLayers.length; ii++) {
userLayers.push(comp.selectedLayers[ii]);
}
} else {
for (ii = 1; ii <= comp.layers.length; ii++) {
userLayers.push(comp.layers[ii]);
}
}
if (userLayers.length === 0) {
alert('No layers to delete keys from!');
return;
}
for (ii = 0; ii < userLayers.length; ii++) {
var layer = userLayers[ii];
var wasSelected = layer.selected;
for (var jj = 1; jj <= layer.numProperties; jj++) {
deleteKeys(comp.time, layer, layer.property(jj).name);
}
layer.selected = wasSelected;
}
}
/**
* Deletes keys with data
*
* @param {number} curTime Current time to delete on
* @param {Layer} curLayer Layer or prop group to run through
* @param {string} propGroup Current prop group / layer
*/
function deleteKeys(time, layer, propGroup) {
var thisPropGroup = layer.property(propGroup);
var numProps;
try {
numProps = thisPropGroup.numProperties;
} catch (err) {}
if (!numProps) {
return;
}
for (var ii = 1; ii < numProps + 1; ii++) {
var curProp = thisPropGroup.property(ii);
if (curProp.numProperties !== undefined) {
deleteKeys(time, thisPropGroup, curProp.name);
} else if (curProp.numKeys !== 0) {
if (curProp.keyTime(curProp.nearestKeyIndex(time)) == time) {
curProp.removeKey(curProp.nearestKeyIndex(time));
}
}
}
}
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert('Open a comp!');
return;
}
app.beginUndoGroup('Delete Keys at Time');
deleteKeysAtTime(comp);
app.endUndoGroup();
})();