Skip to main content
Known Participant
April 28, 2023
Question

Can scripts move keyframes on the timeline?

  • April 28, 2023
  • 1 reply
  • 1612 views

 

Hello,

 

 I managed to google and use AI to write this script - it crops the selected layer to the layer above. Works well!

 

But I'd also like it to move the last two keyframes on the position property to the layers new outpoint.

 

I'm not sure if scripts are able to move keyframes like that? I haven't been able to find anything that works when adding it to this script.

 

var selectedLayer = app.project.activeItem.selectedLayers[0];
var layerAbove = selectedLayer.index - 1;
var layerAboveDuration = app.project.activeItem.layer(layerAbove).outPoint;
selectedLayer.outPoint = layerAboveDuration;

 

Any suggestions would be amazing.

 

Thank you

1 reply

Dan Ebberts
Community Expert
Community Expert
April 28, 2023

Unfortunately, there's no mechanism for moving keyframes. You have to create a new keyframe at the desired time, copy over all the attributes of the keyframe you want to copy, then delete the copied keyframe.

Known Participant
April 28, 2023

 

Thank you Dan,

Does that make for an unrelaible or slow script?

Or can a script be written that can run off my existing code above, that can copy those two last keyframes and paste it to the layers new outpoint - while keeping the realtive distance between the two keyframes correct?

 

Dan Ebberts
Community Expert
Community Expert
April 28, 2023

>Does that make for an unrelaible or slow script?

No, not particularly--it shouldn't.

The problem is that that are a lot of keyframe attributes you have to consider (and as I recall, order is importatnt). You might want to get your hands on a copy of Jeff Almasol's rd: Scooter script, which I think you can get from aescripts.com (I'm assuming it's still a .jsx file so you can see the code) and look at how he handles "moving" a keyframe.