Rippling in a Script

amendegw wrote on 9/28/2011, 5:56 PM
First my disclaimer... I have very little ideal what I'm doing!!

Second, I'm about ready to give up on this effort, so if things are too complicated, any readers of this post should not spend much time on this problem.

That said, over in this thread: Extending the head material of clip, Rory Cooper made the request to extend the beginning of a video event with a still as a header.

So, my thoughts were: it takes about 15 secs to move the cursor to the beginning of an event, take a snapshot and then insert the snapshot at the beginning of the event. With Auto Ripple on, everything is properly shifted on the Timetline. How complicated can it be to write a script to preform the same function? Well, either I'm making this much more complicated than it needs to be, or it is, indeed, more complicated than I thought.

After learning/copying/plagiarizing much code in this forum (thanks to all!!), I got it pretty much to work in hardcoded/debug form. Except one or two things.

My biggest problem is that I can't get my script to ripple (either in the code, or manually setting Auto Ripple). Here's what I get

Before:

After:

The other (lesser) problem is... it would be nice to be able to insert the still on the same track as the original Video media.

Edit: The following downloads have been fixed with the code listed the following post

Here's the bare script as a .dll SnapShotDLL.zip

Here's the VS2010 Project: SnapShotProj.zip

Here's a code listing (remember, lots of hardcoded statements & Debug code):
using System;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;

namespace SnapShot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void goButton_Click(object sender, EventArgs e)
{
// secs will need to be set from the Form
Timecode secs = Timecode.FromSeconds(5);
Environment.SpecialFolder special = Environment.SpecialFolder.MyPictures;
string path = Environment.GetFolderPath(special) + "\\aaaSnapTest.png";
Media mySnapShot = new Media(path);

// save the Initial Properties
VideoRenderQuality saveQuality = EntryPoint.myVegas.Project.Preview.RenderQuality;
VideoPreviewSize saveSize = EntryPoint.myVegas.Project.Preview.PreviewSize;
int iCtr = 0;
Timecode saveCursorPosition = EntryPoint.myVegas.Transport.CursorPosition;

try
{
// We want to capture at Best Full, so set the Preview Settings
EntryPoint.myVegas.Project.Preview.RenderQuality = VideoRenderQuality.Best;
EntryPoint.myVegas.Project.Preview.PreviewSize = VideoPreviewSize.Full;
EntryPoint.myVegas.UpdateUI();

foreach (Track aTrack in EntryPoint.myVegas.Project.Tracks)
{
if (aTrack.IsVideo())
{
foreach (VideoEvent vEvent in aTrack.Events)
{
if (vEvent.Selected)
{
iCtr++;
if (iCtr == 1)
{
//logic will go here for either start of finish of Event
EntryPoint.myVegas.Cursor = vEvent.Start;
EntryPoint.myVegas.UpdateUI();

//Save the SnapShot (hardcoded for testing)
// eventually we'll want to put code here for unique file name;
EntryPoint.myVegas.SaveSnapshot(path, ImageFileFormat.PNG);

// save the cursor position so we know where to add the Picture
saveCursorPosition = vEvent.Start;

// move the event to the right by the length of the still
vEvent.Start = saveCursorPosition + secs;

//MessageBox.Show(vEvent.ActiveTake.Name);
}
}
}
}
}

// if nothing has been selected, inform the user
if (iCtr != 1)
{
MessageBox.Show("You must select as least one and only one Video Event, Please try again");
}
else
{
// Here we add a new Video Track and insert the picture we just created
VideoTrack newTrack = EntryPoint.myVegas.Project.AddVideoTrack();
VideoEvent newEvent = newTrack.AddVideoEvent();
newEvent.Length = secs;
newEvent.Start = saveCursorPosition;
newEvent.Takes.Add(new Take(mySnapShot.GetVideoStreamByIndex(0)));
}
}
catch (Exception eCapture)
{
MessageBox.Show(eCapture.Message);
}
// Restore Preview Settings
EntryPoint.myVegas.Project.Preview.RenderQuality = saveQuality;
EntryPoint.myVegas.Project.Preview.PreviewSize = saveSize;
EntryPoint.myVegas.UpdateUI();
this.Dispose();
}

private void cancelButton_Click(object sender, EventArgs e)
{
this.Dispose();
}

private void Form1_Load(object sender, EventArgs e)
{
descLabel.Text = "This is a really crude attempt at taking a snapshot of the\r\n" +
"first frame of a video event and placing that snapshot as\r\n" +
"a header to the event. Lots of hardcoding and debug code";
}
}


public class EntryPoint
{
//In order to access the myVegas object in the Windows Form, it must be have public access
public static Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;
try
{
// Display the Windows Form
Form1 form1 = new Form1();
form1.ShowDialog();

}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}


Phew!!
...Jerry

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9

Comments

amendegw wrote on 9/29/2011, 7:25 AM
Well, I got the pseudo-ripple to work by manually moving all events to the right of the cursor positon. I'll continue to play with this script. (although I'm still not sure I know what I'm doing).

//Move all the Video tracks to the right of Save Position

foreach (Track tTrack in EntryPoint.myVegas.Project.Tracks)
{
// We must create a list to save the events else when we move an event we may be selecting it again
List<TrackEvent> selectedEvents = new List<TrackEvent>();
foreach (TrackEvent tEvent in tTrack.Events)
{
//Check to see if the start position of the event is to the right of the saved cursor
if (tEvent.Start >= saveCursorPosition)
{
//if it is add ti to the saved list
selectedEvents.Add(tEvent);
}
}
//Now loop thru the saved list ad move each by the number of seconds
foreach (TrackEvent tsEvent in selectedEvents)
{
tsEvent.Start = tsEvent.Start + secs;
}
}


...Jerry

Edit: Closer, but it's still not quite working. I'll keep trying.
Edit2: After mucho debugging I figured out what my problem was... within my foreach loop I was moving events. Then the next time thru, at times the next event was ignored. The solution was to save the events and then move them. Corrected code is listed in the code block abover.

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9

Gary James wrote on 10/3/2011, 2:46 PM
This will work for video events that do not belong to a group. But if you try to move a grouped event (like a clip of video with an associated clip of audio), only the video event will be moved. You'll need to iterate all events on other tracks that are grouped with your moved video events, and move them too!

You're discovering what I've found in working with the Vegas API. The API pretty much only exposes the primitive functions that are called by higher level code internal to Vegas that implements the actions available via the Vegas buttons and menus.

Gary ...
RogFromTheGarage wrote on 12/5/2016, 8:16 PM

Jerry, I know this is an old post, but I have just started writing my own Vegas extensions and ran into the same problem you described above. I was iterating through the event using a foreach and when I move an event that then overlaps with another event the for each was re-selecting the moved event. Storing all event in a list first and then walking that list fixed it. Thanks.