Activity › Forums › Adobe After Effects Expressions › Bumpy position keys
-
Bumpy position keys
Posted by S. Marcotte on January 28, 2009 at 5:05 pmHello – I have some bumpy position keyframes along a 1000-frame layer. The Smoother isn’t working as well as I would hope. Is there an expression that could delete every second key for me? I have a feeling that would help a good deal. Thanks very much.
James Young replied 3 years, 11 months ago 7 Members · 10 Replies -
10 Replies
-
Dan Ebberts
January 28, 2009 at 6:04 pmAn expression to ignore every other keyframe would be tricky, but this script should remove all even numbered keys for you:
{
var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem){
var myLayers = myComp.selectedLayers;
if (myLayers.length > 0){
var myLayer = myLayers[0];
var myProperty = myLayer.property(“Position”);
for (var i = myProperty.numKeys; i > 0; i–){
if (i%2 == 0) myProperty.removeKey(i);
}
}else{
alert(“No layer selected”);
}
}else{
alert (“No comp selected”);
}
}Just save it as a .jsx file, make sure your layer is selected, then File > Scripts > Run Script File and navigate to the script.
Dan
-
S. Marcotte
January 28, 2009 at 6:13 pmOK – That’s impressive. Just like that, off the top of your head. And it works.
-
Jhem Murray
June 4, 2013 at 4:24 pmDan you are a legend…how do you know all this stuff? incredible…
-
Navarro Parker
February 1, 2017 at 2:16 amHey Dan!
I just applied this to an auto-traced mask and it didn’t remove any keyframes. Are mask KFs something different?
-
Dan Ebberts
February 1, 2017 at 4:14 amIt should work if you change this line to point to the property with the keyframes:
var myProperty = myLayer.property(“Position”);
Dan
-
Mike Horn
July 14, 2017 at 2:19 pmThank you Dan! This script just saved the day for me. What would I change to make to make it remove odd keyframes instead of even?
Also, is there a way to target multiple properties? For example I’d like to target all the properties within a corner pin effect so:
effect(“Corner Pin”)(1)
effect(“Corner Pin”)(2)
effect(“Corner Pin”)(3)
effect(“Corner Pin”)(4)Or can you only specify one property at a time?
-
Mike Horn
July 14, 2017 at 2:44 pmActually, you already answered the first part of my question Dan… found it in another post of yours: you just add a negative infront of the “0” in line 9:
if (i%2 == -0) myProperty.removeKey(i);I’m still curious how I’d write multiple properties though if anyone knows.
Thanks!
-
Mike Horn
July 14, 2017 at 3:07 pmTo answer my own question again about targeting multiple properties… this might not be the best method, but simply copying and pasting another instance of the code for each property works. Here’s what I used to target each property of the 4 Corner Pin properties:
{
var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem){
var myLayers = myComp.selectedLayers;
if (myLayers.length > 0){
var myLayer = myLayers[0];
var myProperty = myLayer.effect("Corner Pin")(1);
for (var i = myProperty.numKeys; i > 0; i--){
if (i%2 == -0) myProperty.removeKey(i);
}
}else{
alert("No layer selected");
}
}else{
alert ("No comp selected");
}
}
//
{
var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem){
var myLayers = myComp.selectedLayers;
if (myLayers.length > 0){
var myLayer = myLayers[0];
var myProperty = myLayer.effect("Corner Pin")(2);
for (var i = myProperty.numKeys; i > 0; i--){
if (i%2 == -0) myProperty.removeKey(i);
}
}else{
alert("No layer selected");
}
}else{
alert ("No comp selected");
}
}
//… and keep repeating as much as you want for as many different effects and properties.
-
Dario Linke
June 17, 2021 at 8:25 amHey Dan
I’m probably 12 years late, but for some reason this script isn’t working for me. Maybe After Effects changed the way it uses scripts? Is there an updated version of this script for CC 2020?
Thanks a lot!
Dario
-
James Young
June 7, 2022 at 11:31 pmHey Dario,
I’m sure you’re long since done what you needed this for, but for anyone still looking to get this to work, there were some formatting errors in the original code (possibly due to website upgrades, etc.):
{
var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem){
var myLayers = myComp.selectedLayers;
if (myLayers.length > 0){
var myLayer = myLayers[0];
var myProperty = myLayer.property(“Position”);
for (var i = myProperty.numKeys; i > 0; i–){
if (i%2 == -0) myProperty.removeKey(i);
}
}else{
alert(“No layer selected”);
}
}else{
alert (“No comp selected”);
}
}
Reply to this Discussion! Login or Sign Up