Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
>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.
Copy link to clipboard
Copied
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"));
Copy link to clipboard
Copied
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.