Invert Regions Script

iEmby wrote on 8/30/2024, 10:55 PM

Hi guys

as i created a code which is for finding empty or blank spaces in project.

so i follow these steps.

  • select all events
  • add regions on every event
  • invert regions
  • deselect events

so those inverted regions will be EMPTY SPACES in project.

but my invert region code is not doing it accurately

look

so can anybody fix it ??

this is the code i am using

private void InvertRegions(Vegas vegas)
{
    var regions = vegas.Project.Regions;

    // Calculate the project length
    Timecode projectLength = vegas.Project.Length;

    // Create a list to hold the new regions to be added
    var newRegions = new List<ScriptPortal.Vegas.Region>();

    // Calculate the total number of regions to process
    int totalRegions = (regions.Count > 0) ? (regions.Count + 2) : 1; // +2 for potential start and end regions

    // Add a new region from the start of the project to the first existing region
    if (regions.Count > 0)
    {
        var firstRegion = regions[0];
        if (firstRegion.Position > Timecode.FromNanos(0))
        {
            var newRegion = new ScriptPortal.Vegas.Region(Timecode.FromNanos(0), firstRegion.Position, "Empty Space");
            newRegions.Add(newRegion);
        }
    }
    else
    {
        // If there are no existing regions, add a single region covering the entire project
        var newRegion = new ScriptPortal.Vegas.Region(Timecode.FromNanos(0), projectLength, "Empty Space");
        newRegions.Add(newRegion);
    }

    // Add regions in the gaps between existing regions
    for (int i = 0; i < regions.Count - 1; i++)
    {
        var currentRegion = regions[i];
        var nextRegion = regions[i + 1];

        if (nextRegion.Position - currentRegion.Position - currentRegion.Length > Timecode.FromNanos(0))
        {
            var newRegion = new ScriptPortal.Vegas.Region(currentRegion.Position + currentRegion.Length, nextRegion.Position - currentRegion.Position - currentRegion.Length, "Empty Space");
            newRegions.Add(newRegion);
        }
    }

    // Add a new region from the end of the last existing region to the end of the project
    if (regions.Count > 0)
    {
        var lastRegion = regions[regions.Count - 1];
        if (projectLength - (lastRegion.Position + lastRegion.Length) > Timecode.FromNanos(0))
        {
            var newRegion = new ScriptPortal.Vegas.Region(lastRegion.Position + lastRegion.Length, projectLength - (lastRegion.Position + lastRegion.Length), "Empty Space");
            newRegions.Add(newRegion);
        }
    }
    regions.Clear();

    // Add the new regions
    foreach (var newRegion in newRegions)
    {
        regions.Add(newRegion);
    }
}

 

Last changed by iEmby

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

-----------------------------------------------

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

-----------------------------------------------

INTERNAL GRAPHIC CARD (iGPU)

------------------------------------------------

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

-----------------------------------------------

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

Some useful creations by me including VEGAS Scripts

https://getopensofts.blogspot.com/

 

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)