Hi Folks, this script may be useful to someone.
It does similar what "Multicamera Editing mode does by holding Ctrl+Click"; but now you just have to select any event, video or audio, grouped or not.
It does;
1º - It creates a Marker at cursor position;
2º - It makes a Split;
3º - It makes a crossfade of 1 second;
4º - Then, it deletes the marker.
It can be useful in a lot of scenarios.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
private Marker cursorMarker;
public void Main(Vegas vegas)
{
myVegas = vegas;
// Add a marker at the current cursor position and keep track of it
AddMarkerAtCursor();
// Split events at marker positions
foreach (Marker myMarker in myVegas.Project.Markers)
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Selected)
{
if (evnt.Start < myMarker.Position && evnt.End > myMarker.Position)
{
Timecode splitPoint = myMarker.Position - evnt.Start;
evnt.Split(splitPoint);
// Extend the event before the split by 1 second
ExtendEventLength(evnt, 1, "Seconds");
}
}
}
}
}
// Delete the marker after all operations
RemoveMarker();
}
private void AddMarkerAtCursor()
{
try
{
Timecode cursorPosition = myVegas.Transport.CursorPosition;
cursorMarker = new Marker(cursorPosition, "Cursor Marker");
myVegas.Project.Markers.Add(cursorMarker);
}
catch (Exception ex)
{
MessageBox.Show(
"Failed to add marker: " + ex.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void RemoveMarker()
{
try
{
if (cursorMarker != null)
{
myVegas.Project.Markers.Remove(cursorMarker);
}
}
catch (Exception ex)
{
MessageBox.Show(
"Failed to remove marker: " + ex.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ExtendEventLength(TrackEvent trackEvent, double extendValue, string timecodeType)
{
try
{
switch (timecodeType)
{
case "Frames":
// Calculate the length in frames for 1 second
double framesPerSecond = trackEvent.Length.FrameRate;
long lengthInFrames = (long)(1 * framesPerSecond);
trackEvent.Length = Timecode.FromFrames(trackEvent.Length.FrameCount + lengthInFrames);
break;
case "Seconds":
// Extend by 1 second
trackEvent.Length = Timecode.FromSeconds(trackEvent.Length.ToMilliseconds() / 1000.0 + extendValue);
break;
default:
MessageBox.Show("Invalid timecode type selected.");
break;
}
}
catch (Exception ex)
{
MessageBox.Show(
"Something went wrong: " + ex.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
}
