Adding Effect/Keyframes to Track

2G wrote on 5/19/2004, 7:30 PM
I'm trying to add an effect to a track then add keyframes at markers to adjust the effect. For some reason, I can't seem to create a keyframe. I've reduced it down to a 2 line test case:

var keyf = new Keyframe( new Timecode(2000) );
keyf.Type = VideoKeyframeType.Hold;

I run this script and get an Invalid Keyframe error on the second line (actually doing anything with keyf on the next line causes the same error). I tried adding the keyframe to the track effect I created and then set the Type. I then got a "Failed to Add Keyframe" msg. But then after the script ended, the keyframe appeared on the track.

I'm obviously missing something here. I scoured all the scripts in the toolkit and scanned Sundance. I can't find a single example script that adds an effect keyframe.

Can someone explain why the keyframe I created is invalid? Am I going about this wrong?

2G

Comments

jetdv wrote on 5/19/2004, 8:08 PM
While you've created a new keyframe, you haven't yet applied it to an event. You have to do that before you can do the second line. You really need to read everything at the URL I put in your previous question. Specifically, look at the stuff on this page:

http://www.ayizwe.net/VegasScripts/FAQ.html

Bottom line, you need something like:
keyframe.Add(keyf)

where "keyframe" is your list of keyframes for this event.
2G wrote on 5/19/2004, 9:35 PM
I did read through the FAQ. I didn't find anything in there that says you can't call methods on a keyframe object until it's added. Seems to me that restrictions like this should be right in the object/method API doc. I scanned for "keyframe" in the FAQ and see nothing that would explain this. I also have done extensive review of the API doc which is good about telling the method names and constructors, but it pretty short on explanation on how to use the objects. Sorry if I'm overlooking it.

But I'm still not there. I'm now getting two keyframes with the following code. One where I expect it to be with the "Hold" type set, and one at the cursor location with the "Preset" value. If this is documented as well to work this way, I'm just dense and blind. When I put message boxes up showing the keyframes count, it adds another keyframe on the "keyf.Preset =" statement. I can't believe that assigning an attribute to an object at one timecode has the intended effect of creating a separate object at the cursor location and assigning the attribute to it while not setting it on the intended object.

var keyf = new Keyframe( new Timecode(5) );
effect.Keyframes.Add( keyf );
keyf.Preset = "Translucent Blue Border"; <=== creates new keyframe @cursor and sets it to blue preset
keyf.Type = VideoKeyframeType.Hold; <=== sets the correct keyframe to Hold

What am I doing wrong? How do I set the preset value on the object I'm trying to set it on?

BTW, this V5.0a.

2G
2G wrote on 5/19/2004, 9:41 PM
One more thing... don't know if it matters, but the "effect" object I'm adding the keyframe to is a Border effect that was added to the track effects, not to an event's effects.
2G wrote on 5/20/2004, 7:24 AM
Adding a statement to move the cursor to the same location where I'm putting the keyframe fixed this. But in my opinion, this can't be working as designed. I'm past it, but I consider this to be working around a bug that should be fixed. Or at least it should be explained that this behavior is indeed intended and why I should want it to work like it does.