Group Events Contained Within Regions

Charriii5 wrote on 11/25/2025, 3:02 PM

Hi everyone!

While these forums have been a great source for helping me troubleshoot VEGAS Pro in the past, I've been browsing a lot more recently. I've been tinkering with its native features and there are a few that I never thought I'd have a use for that are now crucial to my workflow, so I've been coming back here to see if there were any resources here that would help further.

One thing that I realized was helping a lot were Scripts, and have seen a lot of users share theirs here, so I wanted to contribute as well. I wanted to share it on its own post so it could be easily found.

I work with Groups a lot, since I usually deal with hundreds of Events on my Timeline on any given Project. Selecting each block of Events and Grouping them (literally hundreds of times depending on the Project) does get old after a while. I wondered if there was a way to just Group the Events on one Track with whatever was on the Track above or below it, but I wasn't finding anything online, nor on any of the available Extensions others have created.

After a while of reading through some of the posts here, I came to realize that maybe this could be done through Grouping whatever was on any given Track, contained within a Region. While I'm no programmer, I did my best to interpret the code I found in tutorials from users here, as well as doing my best to guess if I was using the API's definitions and structures correctly.

After a lot of trying to figure out why it wasn't working, I eventually landed on this, which I hope will help someone else the way you guys have helped me!

using System;
using System.Collections.Generic;
using ScriptPortal.Vegas;public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        // Go through each Region in the active Project's Timeline
        foreach (Region region in vegas.Project.Regions)
        {
            // Create a Group at each Region
            TrackEventGroup grp = new TrackEventGroup();
            vegas.Project.Groups.Add(grp);

            // List to hold the Events within each Region's time range
            List<TrackEvent> eventsToGroup = new List<TrackEvent>();

            // Apply to all Tracks in the active Project
            foreach (Track myTrack in vegas.Project.Tracks)
            {
                // Apply to all Events in any given Track
                foreach (TrackEvent evt in myTrack.Events)
                {
                    // Check if the Events are within the Region's Start Position and End time
                    if (evt.Start >= region.Position && evt.End <= region.End)
                    {
                        // Add the Event to the list of Events to be Grouped
                        eventsToGroup.Add(evt);
                    }
                }
            }            // Add all Events that are within the Region to the Group
            foreach (TrackEvent eventToGroup in eventsToGroup)
            {
                grp.Add(eventToGroup);
            }
        }
    }
}

Script Icon:

Please let me know if you find this useful at all! Also, if the code can be simplified or if I did something completely unnecessary here, please let me know. I'm still learning how to interpret and write these, so I don't always know what can and can't be done.

Comments

jetdv wrote on 12/9/2025, 8:03 AM

Out of curiosity, why are you creating the list? You could change:

eventsToGroup.Add(evt);

to

grp.Add(evt);

and then eliminate:

// List to hold the Events within each Region's time range             
List<TrackEvent> eventsToGroup = new List<TrackEvent>();

and

            foreach (TrackEvent eventToGroup in eventsToGroup)
            {
                 grp.Add(eventToGroup);
            }

 

Jack S wrote on 12/9/2025, 8:16 AM

@Charriii5 If you want to group all events on all the tracks on your timeline, there's a far easier way.
Press Ctrl+A then press G.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 12/9/2025, 3:04 PM

@Jack S He's not doing "all events on all tracks". He's doing "all events in each region on the timeline."

Jack S wrote on 12/9/2025, 4:48 PM

@jetdv I was responding to the OP's query

I wondered if there was a way to just Group the Events on one Track with whatever was on the Track above or below it,

I mistook his query. I thought he wanted all the events on one track to be grouped with the events on the tracks above and below. I see now that I was mistaken. I overlooked further down when he mentioned events within regions.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

Charriii5 wrote on 12/9/2025, 9:08 PM

@jetdv

Out of curiosity, why are you creating the list? You could change...

Oh gosh, this is a much better way of handling that. See, I thought that the best course of action would be to create a list of Events that would correspond to each Region which would then check for and add that to a group. I completely failed to realize that having defined "grp", I now had access to ".Add" to fulfill the same function.

Here's the more optimized version of this script (with better formatting since the original copied strangely):

using System;
using System.Collections.Generic;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        // Check each Region in the active Project's Timeline
        foreach (Region region in vegas.Project.Regions)
        {
            // Create a Group at each Region
            TrackEventGroup grp = new TrackEventGroup();
            vegas.Project.Groups.Add(grp);

            // Apply to all Tracks in the active Project
            foreach (Track myTrack in vegas.Project.Tracks)
            {
                // Apply to all Events in any given Track
                foreach (TrackEvent evt in myTrack.Events)
                {
                    // Check if the Events are within the Region's Start Position and End time
                    if (evt.Start >= region.Position && evt.End <= region.End)
                    {
                        // Add Events to Group
                        grp.Add(evt);
                    }
                }
            }
         }
    }
}