Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Bumpy position keys

  • Bumpy position keys

  • S. Marcotte

    January 28, 2009 at 5:05 pm

    Hello – 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.

  • Dan Ebberts

    January 28, 2009 at 6:04 pm

    An 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 pm

    OK – That’s impressive. Just like that, off the top of your head. And it works.

  • Jhem Murray

    June 4, 2013 at 4:24 pm

    Dan you are a legend…how do you know all this stuff? incredible…

  • Navarro Parker

    February 1, 2017 at 2:16 am

    Hey 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 am

    It 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 pm

    Thank 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 pm

    Actually, 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 pm

    To 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 am

    Hey 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

Viewing 1 - 10 of 10 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy