Create script to output start and end time in seconds of region marker

johnny-s wrote on 1/6/2025, 8:41 AM

I may do a bit of batch scripting but have no knowledge of VP scripting. My request is as per topic name to create a script that will output to a text file the start and end times in seconds of region markers on timeline in this typical format. Perhaps some scripting Guru can oblige. Thanks in advance.

The following is an example of 3 sets. Please note that there should be no lines below between each entry, as below I couldn't do this edit/post without the empty lines appearing.

[23]

[899]

[1000]

[2000]

[2030]

[3020]

Last changed by johnny-s

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

Comments

jetdv wrote on 1/6/2025, 9:38 AM

Please note that there should be no lines below between each entry, as below I couldn't do this edit/post without the empty lines appearing.

You can if you select that section of the post and click on the "<>" button.

Here's a way to output information:

This will show you how to go through regions and access the starting and ending times.

Given a little time, I can help combine the two for you.

johnny-s wrote on 1/6/2025, 10:40 AM

Thanks for the tip re:< > and the videos.
 

Perhaps you misunderstood my request, I may not have worded it clearly .I'm not looking to learn scripting. I was hoping for someone to supply the script as per my description. I was thinking that there might be already some code that was already close to my requirements that could be modified. Worst case to do it from blank sheet.

Last changed by johnny-s on 1/6/2025, 10:43 AM, changed a total of 1 times.

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

jetdv wrote on 1/6/2025, 10:50 AM

Something like this?

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;

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

            SaveFileDialog svd = new SaveFileDialog();
            svd.InitialDirectory = "D:\\"; //Change this to where you want it to look by default;
            svd.Filter = "Save Files (*.TXT)|*.txt|All Files (*.*)|*.*";
            svd.FilterIndex = 1;
            svd.RestoreDirectory = true;
            if (svd.ShowDialog() == DialogResult.OK)
            {
                using (StreamWriter fs = new StreamWriter(svd.FileName))
                {
                    foreach (ScriptPortal.Vegas.Region region in myVegas.Project.Regions)
                    {
                        int Start = (int)Math.Round((region.Position.ToMilliseconds() / 1000));
                        int End = (int)Math.Round((region.End.ToMilliseconds() / 1000));
                        fs.WriteLine("[ " + Start.ToString() + "  " + End.ToString() + " ]");
                    }
                }
            }
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas, string scriptFile, XmlDocument scriptSettings, ScriptArgs args)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

johnny-s wrote on 1/6/2025, 11:42 AM

Thank you. I saved it as Region start - end times.cs and put it into the script menu on C:.

I changed one line to ...

svd.InitialDirectory = "D:\VP etc\00 Xtras\Scripts, extensions\Scripts"; //Change this to where you want it to look by default;

 

I am getting an error message 0x80131600 (message missing)

C:\Program Files\VEGAS\VEGAS Pro 22.0\Script Menu\Region start - end times.cs(24) : Unrecognized escape sequence
C:\Program Files\VEGAS\VEGAS Pro 22.0\Script Menu\Region start - end times.cs(24) : Unrecognized escape sequence
C:\Program Files\VEGAS\VEGAS Pro 22.0\Script Menu\Region start - end times.cs(24) : Unrecognized escape sequence

 

Is this //Change this to where you want it to look by default; the default location of the new saved .txt file to be?

Ok. Maybe a save dialog should display?

 

Last changed by johnny-s on 1/6/2025, 11:56 AM, changed a total of 5 times.

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

jetdv wrote on 1/6/2025, 12:14 PM

This line is incorrect:

svd.InitialDirectory = "D:\VP etc\00 Xtras\Scripts, extensions\Scripts";

Notice I have "\\" which equals "\" when decoded. So you have two options:

svd.InitialDirectory = "D:\\VP etc\\00 Xtras\\Scripts, extensions\\Scripts";

or

svd.InitialDirectory = @"D:\VP etc\00 Xtras\Scripts, extensions\Scripts";

Also, I used drive "D". Do you need "D" or "C"?

johnny-s wrote on 1/6/2025, 12:33 PM

Gotcha, thanks. I use drive D:

svd.InitialDirectory = "D:\\My Utils etc\\Makefilm-NVENC\\ToDo"; //Change this to where you want it to look by default;

The test sample output is ...

[ 2  8 ]
[ 11  18 ]

 

Can it be changed ideally to say ?...

[2]
[8]
[11]
[18}

Even without the brackets [] if that's difficult.

Last changed by johnny-s on 1/6/2025, 12:37 PM, changed a total of 4 times.

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

jetdv wrote on 1/6/2025, 12:42 PM

Change

fs.WriteLine("[ " + Start.ToString() + " " + End.ToString() + " ]");

to

fs.WriteLine("[ " + Start.ToString() + " ]");
fs.WriteLine("[ " + End.ToString() + " ]");

 

johnny-s wrote on 1/6/2025, 1:00 PM

Perfect.

Test output with spaces removed:

[1]
[6]
[11]
[18]

Code now:

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;

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

            SaveFileDialog svd = new SaveFileDialog();
            //svd.InitialDirectory = "D:\\VP etc\00 Xtras\Scripts, extensions\Scripts"; //Change this to where you want it to look by default;
            svd.InitialDirectory = "D:\\My Utils etc\\Makefilm-NVENC\\ToDo"; //Change this to where you want it to look by default;
            //svd.Filter = "Save Files (*.TXT)|*.txt|All Files (*.*)|*.*";
            svd.Filter = "Save Files (*.LOG)|*.log|All Files (*.*)|*.*";
            svd.FilterIndex = 1;
            svd.RestoreDirectory = true;
            if (svd.ShowDialog() == DialogResult.OK)
            {
                using (StreamWriter fs = new StreamWriter(svd.FileName))
                {
                    foreach (ScriptPortal.Vegas.Region region in myVegas.Project.Regions)
                    {
                        int Start = (int)Math.Round((region.Position.ToMilliseconds() / 1000));
                        int End = (int)Math.Round((region.End.ToMilliseconds() / 1000));
                        //fs.WriteLine("[ " + Start.ToString() + "  " + End.ToString() + " ]");
                        fs.WriteLine("[" + Start.ToString() + "]");
                        fs.WriteLine("[" + End.ToString() + "]");
                    }
                }
            }
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas, string scriptFile, XmlDocument scriptSettings, ScriptArgs args)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

johnny-s wrote on 1/6/2025, 1:05 PM

Thanks for all of that jetdv, really appreciated.

Just one last query, not a must.

How to output to a fixed named directory and fixed named file txt/log file without dialog user input?

So always output say: D:\\Region-Times\\Region-Times.log

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10

jetdv wrote on 1/6/2025, 1:25 PM

Change:

            SaveFileDialog svd = new SaveFileDialog();
            svd.InitialDirectory = "D:\\"; //Change this to where you want it to look by default;
            svd.Filter = "Save Files (*.TXT)|*.txt|All Files (*.*)|*.*";
            svd.FilterIndex = 1;
            svd.RestoreDirectory = true;
            if (svd.ShowDialog() == DialogResult.OK)
            {
                using (StreamWriter fs = new StreamWriter(svd.FileName))
                {
                    foreach (ScriptPortal.Vegas.Region region in myVegas.Project.Regions)
                    {
                        int Start = (int)Math.Round((region.Position.ToMilliseconds() / 1000));
                        int End = (int)Math.Round((region.End.ToMilliseconds() / 1000));
                        fs.WriteLine("[ " + Start.ToString() + "  " + End.ToString() + " ]");
                    }
                }
            }

To:

            string FileName = "D:\\My Utils etc\\Makefilm-NVENC\\ToDo\\MyFile.txt"; //Change the file name
            using (StreamWriter fs = new StreamWriter(FileName))
            {
                foreach (ScriptPortal.Vegas.Region region in myVegas.Project.Regions)
                {
                    int Start = (int)Math.Round((region.Position.ToMilliseconds() / 1000));
                    int End = (int)Math.Round((region.End.ToMilliseconds() / 1000));
                    fs.WriteLine("[" + Start.ToString() + "]");
                    fs.WriteLine("[" + End.ToString() + "]");
                }
            }

 

johnny-s wrote on 1/6/2025, 1:41 PM

Fabulous. Nice to have both options, thanks so much.

In case you were wondering, my use case for this is the following:

I currently extract sections of a video file, ( basically files that I don't need to transcode again) then concatenate the pieces together. No transcoding takes place.

Step 1.
I load the file into VP selecting a time code in seconds. I mark out the sections I wish to keep with region markers.

Step 2.
I load the same source file into an "Extract" util and then enter the times in seconds at VP's region markers.
With all of the times in seconds entered I then export the pieces.

Step 3.
I then run a "concatenate" util on the pieces to create the final output file.

Doing this avoids a transcode with some stuff that is already not the greatest quality to start with.

Where your script comes into it is (Step 2) it avoids the tedious and occasionally error prone task of entering by eyball the values displayed in VP into the "Extract" util.

Instead I will simply import the script's output values into the "Extract" util.

With for example 5 or 6 sets of regions ( 10/12 times) its error proof and quicker using the script.

I have been doing this for quite some time and only thought of using a script (if possible) today. Thank you very much. 

 

 

Last changed by johnny-s on 1/6/2025, 1:44 PM, changed a total of 4 times.

PC 1:

Intel i9-9900K

32 GB Ram

AMD Radeon XFX RX 7900 XT

Intel UHD 630

Win 10

PC 2:

AMD Ryzen 9 7950X3D 16 core CPU

64 GB Ram

Nvidia 4090 GPU

Intel A770 GPU

Win 11

 

Laptop:

Intel 11th. Gen 8 core CPU. i9-11900K

64 GB Ram

Nvidia RTX 3080 GPU

Win 10