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); } }