Hi guys.. @zzzzzz9125 @Thiago_Sase @jetdv
i create this script for adding region from user input timecode in following format.
00:56:19 - 00:57:34
00:57:37 - 00:58:19
01:01:33 - 01:02:28
01:03:41 - 01:04:53
01:12:16 - 01:13:25
but is taking only starting timecodes (Bold ones) of every line as region's start and end.
i want it to work like
00:56:19 - 00:57:34 ... first one should be region's start and second one regions end
using System; using System.Collections.Generic; using System.Windows.Forms; using ScriptPortal.Vegas; public class EntryPoint { [STAThread] public void FromVegas(Vegas vegas) { // Prompt user for timecodes string input = PromptForTimecodes(); if (string.IsNullOrEmpty(input)) { MessageBox.Show("No timecodes entered. Exiting."); return; } // Parse and sort the timecodes List<Timecode> timecodes = ParseTimecodes(input); if (timecodes.Count == 0) { MessageBox.Show("No valid timecodes were entered. Exiting."); return; } timecodes.Sort(); // Create regions in VEGAS Pro CreateRegionsInVegas(vegas, timecodes); } private string PromptForTimecodes() { using (Form form = new Form()) { form.Text = "Enter Timecodes in HH:MM:SS format (one per line)"; form.StartPosition = FormStartPosition.CenterScreen; form.Size = new System.Drawing.Size(400, 300); TextBox textBox = new TextBox { Multiline = true, Width = 360, Height = 200, ScrollBars = ScrollBars.Vertical, Location = new System.Drawing.Point(10, 10) }; Button okButton = new Button { Text = "OK", DialogResult = DialogResult.OK, Location = new System.Drawing.Point(100, 220) }; Button cancelButton = new Button { Text = "Cancel", DialogResult = DialogResult.Cancel, Location = new System.Drawing.Point(200, 220) }; form.Controls.Add(textBox); form.Controls.Add(okButton); form.Controls.Add(cancelButton); form.AcceptButton = okButton; form.CancelButton = cancelButton; DialogResult result = form.ShowDialog(); return result == DialogResult.OK ? textBox.Text : null; } } private List<Timecode> ParseTimecodes(string input) { List<Timecode> timecodes = new List<Timecode>(); string[] lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); List<string> invalidLines = new List<string>(); foreach (string line in lines) { Timecode timecode; string trimmedLine = line.Trim(); if (TryParseTimecode(trimmedLine, out timecode)) { timecodes.Add(timecode); } else { invalidLines.Add(trimmedLine); } } if (invalidLines.Count > 0) { string invalidLinesMessage = "The following lines were not valid timecodes:\n"; foreach (string invalidLine in invalidLines) { invalidLinesMessage += invalidLine + "\n"; } MessageBox.Show(invalidLinesMessage.TrimEnd(), "Invalid Timecodes", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return timecodes; } private bool TryParseTimecode(string timecodeString, out Timecode timecode) { timecode = null; try { timecode = new Timecode(timecodeString); return true; } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing timecode '{0}': {1}", timecodeString, ex.Message), "Invalid Timecode", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } private void CreateRegionsInVegas(Vegas vegas, List<Timecode> timecodes) { Project project = vegas.Project; if (project == null) { MessageBox.Show("No active project found. Exiting."); return; } if (timecodes.Count < 2) { MessageBox.Show("At least two valid timecodes are required to create regions.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { for (int i = 0; i < timecodes.Count - 1; i++) { Timecode start = timecodes[i]; Timecode end = timecodes[i + 1]; if (start < end) // Ensure that the start is before the end { project.Regions.Add(new Region(start, end - start)); } } MessageBox.Show("Regions created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Failed to create regions: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
can someone please fix it?