I have spent way too much time on this. I've looked at other scripts, and none of the keyframe motion commands seems to make any sense. In the script below,
I have the offset command:
key2.MoveBy(offset);
The "offset" variable is a constant. I would expect this to either move each subsequent keyframe to the same location, or else move it by the same amount relative to the previous keyframe. Instead, it moves the keyframes one way, and then the other. I'm having the same problem with the ByScale command. I've read some of Ed's tutorials, looked at JohnyRoy's examples, and read the API doc a dozen times. Something sure seems screwy.
Any help would be appreciated.
I have the offset command:
key2.MoveBy(offset);
The "offset" variable is a constant. I would expect this to either move each subsequent keyframe to the same location, or else move it by the same amount relative to the previous keyframe. Instead, it moves the keyframes one way, and then the other. I'm having the same problem with the ByScale command. I've read some of Ed's tutorials, looked at JohnyRoy's examples, and read the API doc a dozen times. Something sure seems screwy.
Any help would be appreciated.
/**
* This script will assign 20 keyframes to the each selected event on the first timeline.
* It assigns these events
*
* Copyright 2006 - John H. Meyer
* Last revision, April 25, 2006
*
**/
import System;
import System.Collections;
import System.Text;
import System.IO;
import System.Drawing;
import System.Windows.Forms;
import Sony.Vegas;
var evnt : TrackEvent;
var zero : int = 0;
var max : int = 10;
try {
//Find the selected event
var track = FindSelectedTrack();
if (null == track) // Must select a track
throw "no selected track";
var eventEnum = new Enumerator(track.Events);
if (track.IsVideo()) { // Track must be a video track
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
if (evnt.Selected) {
var vevnt = VideoEvent(evnt);
var EventLength = evnt.Length.ToMilliseconds();
var LogLength = System.Math.Exp((System.Math.Log(EventLength)/max));
var keycollection = vevnt.VideoMotion.Keyframes;
// Check if there is only one keyframe
var videoWidth : int=Vegas.Project.Video.Width;
var offset = new VideoMotionVertex(float(videoWidth/max), float(0));
for (var i=0; i <=max; i++) {
// var NewKeyTimecode = new Timecode(Timecode.FromMilliseconds(int(1 + EventLength - Math.pow(LogLength,i) - i/max)));
var NewKeyTimecode = new Timecode(Timecode.FromMilliseconds(EventLength - EventLength * i/max) );
var key2 = new VideoMotionKeyframe(NewKeyTimecode);
// add the new key frame
vevnt.VideoMotion.Keyframes.Add(key2);
key2.MoveBy(offset);
//MessageBox.Show(int(1 + EventLength - Math.pow(LogLength,i) - i/max));
//MessageBox.Show(int(Math.pow(LogLength,i) ));
}
} //End if keyframes
} //End if selected
eventEnum.moveNext();
} // End While eventEnum
} // End If track.IsVideo
else {
MessageBox.Show("You must select a video track");
}
} catch (e) {
MessageBox.Show(e);
}
function FindSelectedTrack() : Track {
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;