Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can scripts move keyframes on the timeline?

Explorer ,
Apr 27, 2023 Apr 27, 2023

 

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

TOPICS
Expressions
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2023 Apr 27, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2023 Apr 27, 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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2023 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2023 Apr 28, 2023

Just for fun, I wanted to see if I could move a keyframe by using the Edit menu Cut and Paste commands, and it seemed to work. So maybe this is another (easier) option:

var comp = app.project.activeItem;
for (var i = 1; i <= comp.numLayers; i++){  // deselect all layers
	comp.layer(i).selected = false;
}
var layer = comp.layer(1);
var prop = layer.property("Position");
prop.setSelectedAtKey(1,true);  // select first keyframe
app.executeCommand(app.findMenuCommandId("Cut"));
comp.time = 2; // move CTI
app.executeCommand(app.findMenuCommandId("Paste"));
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2023 Apr 28, 2023

Thank you Dan, and I appreciate the suggestion about rd: scooter - I like trying to reverse engineer and figure out has its done. Your script looks interesting and will give it a play.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 25, 2025 Aug 25, 2025
LATEST

I have a script working that moves keyframes on the time really well by deleting, and recreating them. The one property that doesn't work is time remapping though. I guess when those keys get deleted time remapping disappears and there's nothing to recreate the keys on. I haven't been able to figure out a workaround for it, any tips?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines