function time reverse keyframes

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

Hello,
I would want to make a function which reverse the keyframes of the selected properties, but I don't know how to call this "reverseKeyframes" : I don't even know if it exists!
Any idea?
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

Such a built-in function does not exist.
To do this, you need to STORE all key frames along with all of their properties (time, value, interpolation type, keyFrameEase values, etc), delete the keyframes, and "paste",
where "paste" is not simply .paste() (doesnt exist) but the reverse process of storing: .setValueAtTime(newTime, value) for all keys, and rewrite interpolations, replacing inInterpolation by outInterpolations and vice-versa.
Since they is no Key object in the AE Object Model, you must make your own... long but once you have done you find it.. very instructive;)

If you know that all the keyframes are linear, you don't need to copy every single property though, time and value is enough.
On the other hand if you want to reverse a subset of a set of roving keys it can be a little bit cumbersome ;)
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

Ok, thank you! I success to do that, because my script need only work with 2 keyframes :

app.beginUndoGroup("Inversion script");
//ajoute un parametre case lorsqu'on coche l'échelle devient moins en X
var inversion = app.project.activeItem.selectedLayers[0].Effects.addProperty("ADBE Checkbox Control");
inversion.name = "Inversion";
inversion(1).setValue(1);
app.project.activeItem.selectedLayers[0].scale.expression = "inversion = effect(\"" + inversion.name+ "\")(1);\n" +
"if(inversion==1){[-value[0],value[1]];}else{[value[0],value[1]];}";
//alert(app.project.activeItem.selectedLayers[0].scale.name);

//inverse les 2 keyframes de position
var raccourci = app.project.activeItem.selectedLayers[0].position;
var keyValueOne = new Array();
var keyValueTwo = new Array();
var keyTimeOne;
var keyTimeTwo;

keyValueOne = raccourci.keyValue(1);
keyValueTwo = raccourci.keyValue(2);
keyTimeOne = raccourci.keyTime(1);
keyTimeTwo = raccourci.keyTime(2);

app.project.activeItem.selectedLayers[0].property("Position").setValueAtTime(keyTimeOne,[keyValueTwo[0],keyValueTwo[1]]);
app.project.activeItem.selectedLayers[0].property("Position").setValueAtTime(keyTimeTwo,[keyValueOne[0],keyValueOne[1]]);

app.endUndoGroup();
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

But I would just want to know if it's possible to highlight and select the position property in after effects when the script finish?
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

off topic: Why not give a variable name to the layer instead of app.project.activeItem.selectedLayers[0] on every single line ??

For your question: layer.property("Position").selected = true;
Can't remember if it selects all keys along. If not: for (k=1; k<=prop.numKeys; k++) prop.setSelectedAtKey(k, true);
selects all the keys of 'prop' (any keyframable property);

All this is in the scripting guide...

Xavier.
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

beginUndoGroup wrote:off topic: Why not give a variable name to the layer instead of app.project.activeItem.selectedLayers[0] on every single line ??

For your question: layer.property("Position").selected = true;
Can't remember if it selects all keys along. If not: for (k=1; k<=prop.numKeys; k++) prop.setSelectedAtKey(k, true);
selects all the keys of 'prop' (any keyframable property);

All this is in the scripting guide...

Xavier.
OK, thank you very much! And yes, I created a variable, it was my old script I wrote here!
For the layer.property("Position").selected = true; => That was not what I wanted to do (but I don't know if it's possible?) : I wanted that the position property was selected AND that it's highlighted in after effects (like when you press "P" to make the property visible). ANy idea?
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

prop.selected = true; does highlight the property and all of its keyframes.

Now if you want to isolate that property, as when you press M, MM, P, etc... : not possible.
Post Reply