-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectFollowingKeyframes.jsx
More file actions
76 lines (69 loc) · 2.89 KB
/
Copy pathSelectFollowingKeyframes.jsx
File metadata and controls
76 lines (69 loc) · 2.89 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
72
73
74
75
76
// SelectFollowingKeyframes.jsx
// Selects every keyframe AFTER the playhead.
// Works on the selected layers, or on every layer when nothing is selected.
// Walks the whole property tree, so effects, masks, shape contents, text
// animators and Puppet pins are all included. Single undo step.
(function () {
// ---- config (the four scripts in this bundle differ only in MODE) ------
var CFG = {
MODE: "following", // "following" | "previous" | "current" | "workarea"
INCLUDE_PLAYHEAD: false, // following/previous: also take a key sitting exactly on the playhead
ADD_TO_SELECTION: false, // true = keep already-selected keys and add to them
SKIP_LOCKED: true // leave locked layers alone
};
// -----------------------------------------------------------------------
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) return;
var t = comp.time;
var EPS = comp.frameDuration / 4;
var waStart = comp.workAreaStart;
var waEnd = comp.workAreaStart + comp.workAreaDuration;
function isMatch(kt) {
switch (CFG.MODE) {
case "following": return CFG.INCLUDE_PLAYHEAD ? (kt >= t - EPS) : (kt > t + EPS);
case "previous": return CFG.INCLUDE_PLAYHEAD ? (kt <= t + EPS) : (kt < t - EPS);
case "current": return Math.abs(kt - t) < EPS;
case "workarea": return kt >= waStart - EPS && kt <= waEnd + EPS;
}
return false;
}
function walk(group) {
for (var p = 1; p <= group.numProperties; p++) {
var prop;
try { prop = group.property(p); } catch (e) { continue; }
if (!prop) continue;
if (prop.propertyType === PropertyType.PROPERTY) {
selectKeys(prop);
} else {
walk(prop);
}
}
}
function selectKeys(prop) {
var n;
try { n = prop.numKeys; } catch (e) { return; }
if (!n) return;
// separated Position: the keys live on the X/Y/Z followers, not on the leader
try { if (prop.isSeparationLeader && prop.dimensionsSeparated) return; } catch (e) {}
for (var k = 1; k <= n; k++) {
try {
var want = isMatch(prop.keyTime(k));
if (want) prop.setSelectedAtKey(k, true);
else if (!CFG.ADD_TO_SELECTION) prop.setSelectedAtKey(k, false);
} catch (e) {} // hidden / unselectable property
}
}
var layers = comp.selectedLayers.slice(0);
if (layers.length === 0) {
for (var i = 1; i <= comp.numLayers; i++) layers.push(comp.layer(i));
}
app.beginUndoGroup("Select Following Keyframes");
try {
for (var j = 0; j < layers.length; j++) {
if (CFG.SKIP_LOCKED && layers[j].locked) continue;
walk(layers[j]);
}
} finally {
app.endUndoGroup();
}
})();