Activity › Forums › Adobe After Effects Expressions › How can I change the time of one or some keyframes?
-
How can I change the time of one or some keyframes?
Posted by Milad Ghiravani on August 21, 2022 at 1:18 pmHi
How can I change the time of one or some keyframes?
For example like this: setTimeAtKey(keyIndex , newTime)
Dan Ebbertsreplied 4 years, 1 month ago 2 Members · 3 Replies
-
3 Replies
-
Dan Ebberts
August 22, 2022 at 2:20 pmAre you talking about scripting? Unfortunately, you can’t change the time of a keyframe via scripting. You have to create a new keyframe, copy all the attributes of the old one (which can be quite involved and order-sensitive), and delete the old one.
-
Milad Ghiravani
August 23, 2022 at 7:01 amYes, for scripting!
Can you help me, what’s this attributes?
For example on this code:var selectedLayers = app.project.activeItem.selectedLayers;
for (i = 0; i < selectedLayers.length; i++)
{
test(selectedLayers[i]);
}
function test(thisLayer)
{
var spl = thisLayer.selectedProperties.length;
try
{
var selectedKeys = 1;//first keyframe
var newKeyTime = 2;// secounds 2 for example
thisKeyValue = thisLayer.selectedProperties[spl-1].keyValue(selectedKeys);
//*** Add all the attributes But I don't know what?!
thisLayer.selectedProperties[spl-1].removeKey(selectedKeys);//delete old keyframe
//*** Copy values to ney keyframe
thisLayer.selectedProperties[spl-1].setValueAtTime(newKeyTime , thisKeyValue);
}
catch (err) {
alert(err);
}
}Thank you
-
Dan Ebberts
August 23, 2022 at 7:48 amIt’s quite tricky, and it takes a surprising amount of code to do it right. Your best bet might be to get your hands on Jeff Almasol’s rd_Scooter script, which I believe has the code necessary to move keyframes. I think you can still get it from aescripts. The last time I saw it, it was still a .jsx file, not .jsxbin, so you’ll be able to see how he did it.
Reply to this Discussion! Login or Sign Up