I'm a script beginner. I want to implement a function, which can nest selected events into a new project, without opening the new project. I tried the following code, but it reported an error.
using System; using System.IO; using System.Windows.Forms; using ScriptPortal.Vegas; namespace Test_Script1 { public class Class1 { public Vegas myVegas; public void Main(Vegas vegas) { myVegas = vegas; foreach (Track myTrack in myVegas.Project.Tracks) { if (myTrack.IsVideo()) { foreach (TrackEvent evnt in myTrack.Events) { if (evnt.Selected) { MediaStream mediaStream = GetActiveMediaStream(evnt); VideoStream videoStream = (VideoStream)mediaStream; String filePath = mediaStream.Parent.FilePath; String nestedPath = filePath + ".veg"; Project nestedProject = vegas.CreateEmptyProject(); VideoTrack track = nestedProject.AddVideoTrack(); nestedProject.SaveProject(nestedPath); } } } } } public MediaStream GetActiveMediaStream(TrackEvent trackEvent) { try { if (!(trackEvent.ActiveTake.IsValid())) { throw new ArgumentException("empty or invalid take"); } Media media = myVegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath); if (null == media) { MessageBox.Show("missing media"); throw new ArgumentException("missing media"); } MediaStream mediaStream = media.Streams.GetItemByMediaType(MediaType.Video, trackEvent.ActiveTake.StreamIndex); return mediaStream; } catch (Exception e) { MessageBox.Show("{0}", e.Message); return null; } } } } public class EntryPoint { public void FromVegas(Vegas vegas) { Test_Script1.Class1 test1 = new Test_Script1.Class1(); test1.Main(vegas); } }
The problem seems to be on line 28, and when I comment out that line, everything is fine. Can anyone help?