This script should do what you are asking. The script as written will concatenate all the events in the project. If there are other events not shown in your screen grab that you do not want affected or you just want to do selected events you need to change the line
bool ALLEVENTS = true;
to
bool ALLEVENTS = false;
When set to false the script will only concatenate events that are selected (obviously you have to have selected events for this to work).
// Close Gaps For Multiple Tracks
using Sony.Vegas;
using System.Collections.Generic;
public class EntryPoint {
Vegas myVegas;
//Change this to false if you want to affect only selected events
bool ALLEVENTS = true;
public void FromVegas(Vegas vegas)
{
SelectedEvents Selected = new SelectedEvents(vegas,ALLEVENTS);
Selected.SortByStartTime();
for(int i = 0; i < Selected.Events.Count - 1; i++)
{
Selected.Events[i+1].Start = Selected.Events[i].End;
}
}
}
public class SelectedEvents
{
public List Events;
public SelectedEvents(Vegas vegas, bool allevents)
{
Events = new List();
foreach(Track t in vegas.Project.Tracks)
{
foreach(TrackEvent ev in t.Events)
{
if (ev.Selected || allevents) Events.Add(ev);
}
}
}
public void SortByStartTime()
{
Events.Sort((x,y) => x.Start.CompareTo(y.Start));
}
}