-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathkeyReverse.jsx
More file actions
72 lines (53 loc) · 3.26 KB
/
keyReverse.jsx
File metadata and controls
72 lines (53 loc) · 3.26 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
//ReverseKeys just does what it says is does - reverses keyframes
//Just select a bunch of keyframes and the script will reverse them at the playhead
//v0.1 - 25.05.2015
//CC-BY, Nik Ska, 2015
keyReverse = this;
keyReverse.go = function() {
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
var sel = activeComp.selectedLayers;
if(sel.length > 0){
app.beginUndoGroup("reversing keys");
for(var l = 0; l < sel.length; l++){
thisLayer = sel[l];
if(thisLayer.selectedProperties.length > 0){
for(var p = 0; p < thisLayer.selectedProperties.length; p++){
thisProperty = thisLayer.selectedProperties[p];
//if there are more than 1 keyframes selected
if(thisProperty.selectedKeys.length > 1){
var keys = thisProperty.selectedKeys;
var newKeyTime = activeComp.time;
for (var k = 0; k < keys.length; k++) {
//creating a new key
var newKeyIndex = thisProperty.addKey(newKeyTime);
//getting spatial and temporal ease values
if ((thisProperty.propertyValueType == PropertyValueType.TwoD_SPATIAL)
|| (thisProperty.propertyValueType == PropertyValueType.ThreeD_SPATIAL)){
var newKeyInSpatialTangent = thisProperty.keyInSpatialTangent(keys[keys.length - k - 1]);
var newKeyOutSpatialTangent = thisProperty.keyOutSpatialTangent(keys[keys.length - k - 1]);
//setting both value and tangents / easing
thisProperty.setValueAtKey(newKeyIndex, thisProperty.keyValue(keys[keys.length - k - 1]));
thisProperty.setSpatialTangentsAtKey(newKeyIndex, newKeyOutSpatialTangent, newKeyInSpatialTangent)
}
else{
var newKeyInTemporalEase = thisProperty.keyInTemporalEase(keys[keys.length - k - 1]);
var newKeyOutTemporalEase = thisProperty.keyOutTemporalEase(keys[keys.length - k - 1]);
//setting both value and tangents / easing
thisProperty.setValueAtKey(newKeyIndex, thisProperty.keyValue(keys[keys.length - k - 1]));
thisProperty.setTemporalEaseAtKey(newKeyIndex, newKeyOutTemporalEase, newKeyInTemporalEase)
}
//updating time
if(k < keys.length - 1){
newKeyTime += thisProperty.keyTime(keys[keys.length - k - 1]) - thisProperty.keyTime(keys[keys.length - k - 2]);
}
}
}
}
}
}
app.endUndoGroup();
}
}
}
keyReverse.go();