open file script

richjo100 wrote on 10/12/2004, 7:48 AM
Hello all,

I want to script the opening of a file. Exactly the same as File->Open except that I want to limit the user to see only certain file types. I can create the file open dialog as follows:

====================================================

var outputFilePathOrig = ShowOpenFileDialog("AVI Files (*.avi)|*.avi", "AVI File", "init file");


function ShowOpenFileDialog(filter, title, defaultFilename) {
var openFileDialog = new OpenFileDialog();
if (null == filter) {
filter = "All Files (*.*)|*.*";
}
openFileDialog.Filter = filter;
if (null != title)
openFileDialog.Title = title;
openFileDialog.CheckPathExists = true;
openFileDialog.AddExtension = true;
if (null != defaultFilename) {
var initialDir = Path.GetDirectoryName(defaultFilename);
if (Directory.Exists(initialDir)) {
openFileDialog.InitialDirectory = initialDir;
}
openFileDialog.DefaultExt = Path.GetExtension(defaultFilename);
openFileDialog.FileName = Path.GetFileName(defaultFilename);
}
if (System.Windows.Forms.DialogResult.OK == openFileDialog.ShowDialog()) {
return Path.GetFullPath(openFileDialog.FileName);
} else {
return null;
}
}

====================================================

but do not know how to use the file name (outputFilePathOrig ) that Ive obtained to actually open teh file in Vegas. Is this possible?

Thanks
Richard

Comments

jetdv wrote on 10/12/2004, 8:32 AM
You have to manually add the media to the project and to the timeline - both the audio and video must be added separately.

First, you must make sure you have an audio and video track. Briefly, here's the base process that must be followed for both the video and audio (I'm only showing the video half here).

var newEvent : VideoEvent = null;
var take : Take = null;
var stream = null;
var media : Media = null;
var Mtrack : Track = null;

Mtrack = new VideoTrack(0, "Track Name");
Vegas.Project.Tracks.Add(Mtrack);

media = new Media(outputFilePathOrig);
stream = media.Streams[0];
newEvent = new VideoEvent(new Timecode(0), stream.length);
Mtrack.Events.Add(newEvent);
take = new Take(stream);
newEvent.Takes.Add(take);


Now repeat the above on an audio track. These two pieces, however, will NOT be grouped. If desired, you can now to that as well if you are using Vegas 5.0b.

You may also want to look at the scripting resources here and here.
richjo100 wrote on 10/13/2004, 3:20 AM
Thanks for your help jetdv!