Extend event length to close gaps

stefan-m2020 wrote on 1/2/2022, 5:52 PM

Hello,

I'm not sure if this is actually a scripting related question.

Inside of a track I have different png files and a lot of space between them.

There is the option "Fill gaps" which is available when you right-click on an empty space.
The problem:
It does not extend existing events but move events, which is wrong.
(At least in my case.)

Let's say I have these 3 png files:
01.png starts at 00:12 and ends at 00:13
02.png starts at 00:21 and ends at 00:22
03.png starts at 00:35 and ends at 00:36

When using Fill gaps it just moves 02.png to 00:14 and 03.png to 00:16.

But I would like to have it this way:
01.png starts at 00:12 at ends at 00:20
02.png starts at 00:21 at ends at 00:34
03.png starts at 00:35 at ends at 00:36 - I will manually edit this

Is there some option for that or can only scripting solve this issue?


Thanks again for any help and best regards

Comments

jetdv wrote on 1/3/2022, 9:00 AM

@stefan-m2020 Yes, a script can do that. Here's a c# script that will do that:
 

using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            Track myTrack = myVegas.Project.Tracks[0]; //zero is the first track

            TrackEvent prevEvent = null; //we will always extend the previous event to reach the current event

            foreach (TrackEvent evnt in myTrack.Events)
            {
                if (prevEvent != null) //if we have a previous event - the first time we will not
                {
                    prevEvent.Length = evnt.Start - prevEvent.Start; //extend it to reach the current event
                }
                prevEvent = evnt;//now the "current" event will become the "previous" event
            }
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

If you haven't, you might also want to take a look at the scripting tutorials at www.jetdv.com. There's lots of good scripting information there as well.

stefan-m2020 wrote on 1/3/2022, 12:09 PM

Hello again, jetdv,

I must admit that my answer from the other thread was meant to be the answer of THIS thread.

The extending events works absolutely brilliant!
Thank you very much.

I hope you could fix the small issue from the other thread.


I did not know the site you posted, I will check it.

Best regards

jetdv wrote on 1/3/2022, 12:21 PM

@stefan-m2020, the website is mine and I've been adding scripting tutorials for about the past year (started end of January last year so quickly approaching the 1 year mark!) I'm going to add this one as a tutorial.