Check this out... Will use the selected video track if a video track is selected - otherwise it will create a new video track. Once all the markers have been processed, the rest of the selected media (if there are more) will be placed at the END of that track at their default lengths.
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
private string[] filenames;
VideoTrack vTrack;
public void Main(Vegas vegas)
{
myVegas = vegas;
string basePath = "D:\\VMedia\\";
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = basePath;
ofd.Filter = "Media File (*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4)|*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4|All Files(*.*)|*.*";
ofd.Multiselect = true;
ofd.Title = "Select the media to use";
DialogResult dr = ofd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
filenames = ofd.FileNames;
vTrack = null;
foreach(Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo() && myTrack.Selected)
{
vTrack = (VideoTrack)myTrack;
break;
}
}
if (vTrack == null)
{
vTrack = new VideoTrack(0, "Added Media");
myVegas.Project.Tracks.Add(vTrack);
}
int currentFile = 0;
for(int i=0; i<myVegas.Project.Markers.Count - 1; i++)
{
if (currentFile >= filenames.Length)
break;
AddFile(filenames[currentFile], i);
currentFile++;
}
for(int i=currentFile; i<filenames.Length; i++)
{
AddFile(filenames[i], -1);
}
}
}
public void AddFile(string filename, int MarkerNum)
{
Timecode startPos;
Timecode length;
Media myMedia = new Media(filename);
if (MarkerNum >= 0)
{
startPos = myVegas.Project.Markers[MarkerNum].Position;
length = myVegas.Project.Markers[MarkerNum + 1].Position - startPos;
}
else
{
startPos = vTrack.Length;
length = myMedia.Length;
}
if (myMedia.HasVideo())
{
MediaStream stream = myMedia.Streams.GetItemByMediaType(MediaType.Video, 0);
if (null != stream)
{
VideoEvent myNewVideoEvent = new VideoEvent(startPos, length);
vTrack.Events.Add(myNewVideoEvent);
Take myNewTake = new Take(stream);
myNewVideoEvent.Takes.Add(myNewTake);
}
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
@jetdv It worked, it's inserting correctly. But, despite the mp4 and mov options appearing, it is only inserting image files, I would like it to be able to insert any type of media, such as: videos and audios. Mostly video.
You can easily change that to the cursor position:
startPos = myVegas.Transport.CursorPosition;
That would be correct for the first one. But in subsequent files, you would want to add them after the event just added so you'll need to set the start position to the end of that last event or move the cursor to after that event.
If you look through the tutorials, there are others that use the cursor position as the target location.
You can easily change that to the cursor position:
startPos = myVegas.Transport.CursorPosition;
That would be correct for the first one. But in subsequent files, you would want to add them after the event just added so you'll need to set the start position to the end of that last event or move the cursor to after that event.
If you look through the tutorials, there are others that use the cursor position as the target location.