Page 1 of 1

Reset value and remove keyframes - possible?

Posted: December 28th, 2010, 4:14 am
by Simma
Hi all,

first sorry for all the questions. Your help is helping me alot in learning this stuff. I though it would be better to post in different threads so that other people easily can find the answer as well by doing a simple Google search.

Anyway, I have a variable called "myCamera" (for example). This layer has keyframes on each frame. I want to remove all keyframes (position, rotation, point of intrest) and reset the transform value. Normally I would click the stopwatch to remove all keyframes, and then I would click the reset button. I searched both the scripting guide and this site, but the only thing I could find was really old and pretty much said it couldn't be done.

best regards,
Simon.

Re: Reset value and remove keyframes - possible?

Posted: December 28th, 2010, 6:16 am
by lloydalvarez
You will need to setup for loops to remove the keyames one by one on each property that has them. When you remove keyframes you probably want to do it in reverse because the numKeyframes value will change when you remove a keyframe and will affect your loop. The CS3 guide is still relevant, very little info in there is wrong or no longer applicable. Where did it say this was not possible?

Lloyd

Re: Reset value and remove keyframes - possible?

Posted: December 28th, 2010, 11:35 am
by Simma
Thank you for your respond Lloyd. I couldn't find anything about removing (exept for remove one keyframe) in the scripting guide. So then I searched here and all I could find was old responses that seemed very complicated. Thought it would be a pretty basic thing. Will have to dig deeper into that. But what about reseting transform values? That I haven't found anything about anywhere.

Re: Reset value and remove keyframes - possible?

Posted: December 28th, 2010, 12:03 pm
by lloydalvarez
Like I said earlier you will need to create a loop and remove the keyframes one by one so the info you find on how to remove one keyframe is what you'll want to use. Not sure there is a way to reset the transforms to their defaults but you can probably calculate them easily. I believe anchor and position is always half the width and half the height, then scale and opacity are 100 and rotation is 0.

-Lloyd

Re: Reset value and remove keyframes - possible?

Posted: December 28th, 2010, 12:09 pm
by Simma
Thank you Lloyd, will try to get a loop working.

Re: Reset value and remove keyframes - possible?

Posted: December 29th, 2010, 3:42 pm
by Simma
Got it working, here's the code in case anyone needs it in the future:

Code: Select all

var myComp = app.project.activeItem;
var myLayer = myComp.layer(1);

var numberKeys = myLayer.rotation.numKeys;

for (var i=numberKeys; i>0; i --) {
    myLayer.rotation.removeKey(i);
Thank you for your help.