I'm trying to create a script that renders the audio from the selected event on the timeline in .wav format and imports it back into the timeline with a take along with the original audio from the selected event, but I don't know the logic for rendering the audio or how to import the audio back with a take. If anyone can help I would be grateful.
using System; using System.IO; using ScriptPortal.Vegas; using System.Windows.Forms; namespace RenderSelectedAudioToNewTake { public class EntryPoint { public void FromVegas(Vegas vegas) { try { // Check if there are selected audio events on the timeline if (!HasSelectedAudioEvents(vegas.Project)) { System.Windows.Forms.MessageBox.Show("Please, Select the Audio Event in Timeline.", "Message"); return; } // Get the selected audio event on the timeline AudioEvent selectedEvent = FindFirstSelectedAudioEvent(vegas.Project); if (selectedEvent == null) { System.Windows.Forms.MessageBox.Show("No Audio Events Selected in the Timeline.", "Message"); return; } // Get the file path of the audio file associated with the selected event string audioPath = selectedEvent.ActiveTake.MediaPath; // Render a copy of the audio from the selected event in .wav format in the same directory as the original file "Inserte here the logic to render a copy of the selected event in .wav format using native Vegas resources." //Importa a cópia do áudio renderizado de volta para a timeline como um Take "Insert here the logic to import back as a Take the rendered copy of the selected event in .wav format using native Vegas resources." } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("An Error Has Occurred: " + ex.Message, "Error"); } } // Method to check if there are selected audio events on the timeline private bool HasSelectedAudioEvents(Project project) { foreach (Track track in project.Tracks) { if (track.IsAudio()) { foreach (TrackEvent trackEvent in track.Events) { if (trackEvent.Selected && trackEvent.IsAudio()) { return true; } } } } return false; } // Method to find the first selected audio event on the timeline private AudioEvent FindFirstSelectedAudioEvent(Project project) { foreach (Track track in project.Tracks) { if (track.IsAudio()) { foreach (TrackEvent trackEvent in track.Events) { if (trackEvent.Selected && trackEvent.IsAudio()) { return trackEvent as AudioEvent; } } } } return null; } } }