I have been trying to write a simple script for 3 days.The script will load photos from the folder
d:\photo
The photos are name
1.png 2.png 3.png 4.png ... 9.png 10.png
Each photo should last as much time as the corresponding number in the table of numbers, for example
1 second 1 second 1 second 2 seconds ... 1 second 1 second 14 seconds
I tried to write something like that
Based on the manual and other sources, I wrote this:
using System.Windows.Forms;
using Sony.Vegas; // old Vegas
//using ScriptPortal.Vegas; // VEGASA 14 or 15
using System; // need to String
using System.Text;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
public class EntryPoint {
public void FromVegas(Vegas vegas) {
AddVideoEvent(vegas, "\"D:\photo\\1.png\"", Timecode.FromSeconds(2), Timecode.FromSeconds(2));
MessageBox.Show("hello world");
}
VideoEvent AddVideoEvent(Vegas vegas, String mediaFile, Timecode start, Timecode length)
{
Media media = new Media(mediaFile);
VideoTrack track = vegas.Project.AddVideoTrack();
VideoEvent videoEvent = track.AddVideoEvent(start, length);
Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
return videoEvent;
}
}
Unfortunately, this does not work an error occurs
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Media stream not specified. at Sony.Vegas.Take.AddSelf(UInt32 trackID, Int64 eventID, MediaType mediaType) at Sony.Vegas.TrackEvent.AddTake(MediaStream mediaStream) at EntryPoint.AddVideoEvent(Vegas vegas, String mediaFile, Timecode start, Timecode length) at EntryPoint.FromVegas(Vegas vegas) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Sony.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName) at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)