ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Bumpy position keys

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Serge Marcotte
Bumpy position keys
on Jan 28, 2009 at 5:05:51 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.



Return to posts index

Dan Ebberts
Re: Bumpy position keys
on Jan 28, 2009 at 6:04:45 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



Return to posts index

Serge Marcotte
Re: Bumpy position keys
on Jan 28, 2009 at 6:13:51 pm

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



Return to posts index


Jhem Murray
Re: Bumpy position keys
on Jun 4, 2013 at 4:24:51 pm

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


Return to posts index

Navarro Parker
Re: Bumpy position keys
on Feb 1, 2017 at 2:16:11 am

Hey Dan!

I just applied this to an auto-traced mask and it didn't remove any keyframes. Are mask KFs something different?


Return to posts index

Dan Ebberts
Re: Bumpy position keys
on Feb 1, 2017 at 4:14:48 am

It should work if you change this line to point to the property with the keyframes:

var myProperty = myLayer.property("Position");


Dan



Return to posts index


Mike Horn
Re: Bumpy position keys
on Jul 14, 2017 at 2:19:29 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?


Return to posts index

Mike Horn
Re: Bumpy position keys
on Jul 14, 2017 at 2:44:48 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!


Return to posts index

Mike Horn
Re: Bumpy position keys
on Jul 14, 2017 at 3:07:47 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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]