I'm trying to create a script that finds and selects in timeline only text events that have a single line of text. But I can't get the script to work. Can anyone help me with this?
using System; using ScriptPortal.Vegas; public class EntryPoint { private static Vegas myVegas; // Main method called by Vegas Pro public void FromVegas(Vegas vegas) { try { myVegas = vegas; // Perform the search and selection operation SelectSingleLineTextEvents(); // Update the Vegas Pro user interface myVegas.UpdateUI(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); // Here you can handle the error appropriately if needed } } // Selects single-line text events private static void SelectSingleLineTextEvents() { if (myVegas == null) { throw new InvalidOperationException("Vegas was not initialized correctly."); } foreach (Track track in myVegas.Project.Tracks) { foreach (TrackEvent trackEvent in track.Events) { // Check if it is a video text event and has a single line of text if (IsTextEvent(trackEvent) && HasSingleLineText(trackEvent)) { trackEvent.Selected = true; // Select the event } } } } // Checks if the event is a video text event private static bool IsTextEvent(TrackEvent trackEvent) { return trackEvent.MediaType == MediaType.Video && trackEvent.ActiveTake != null && trackEvent.ActiveTake.Media != null && trackEvent.ActiveTake.Media.IsGenerated(); } // Checks if the text event contains only one line of text private static bool HasSingleLineText(TrackEvent trackEvent) { string text = GetEventText(trackEvent); return !string.IsNullOrEmpty(text) && !text.Contains(Environment.NewLine); } // Gets the text from the video event using OFX effects private static string GetEventText(TrackEvent trackEvent) { Media media = trackEvent.ActiveTake.Media; foreach (Effect effect in media.Effects) { OFXEffect ofxEffect = effect.OFXEffect; if (ofxEffect != null) { // Find the text parameter by the name "Text" OFXStringParameter textParam = ofxEffect.FindParameterByName("Text") as OFXStringParameter; if (textParam != null) { return textParam.Value; } } } return string.Empty; } }