@jetdv@zzzzzz9125 Please, could you help me to create a script that removes transitions from selected events. I've tried a lot of ways, but nothing works.
@Thiago_Sase Basically, take the script that I wrote to FIND transitions and modify it to look at only selected events and then remove them. This is a quick update to that script but I have not tested it.
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo())
{
foreach (VideoEvent vEvnt in myTrack.Events)
{
if (vEvnt.Selected)
{
RemoveAnyTransition(vEvnt.FadeIn);
RemoveAnyTransition(vEvnt.FadeOut);
}
}
}
}
}
public void RemoveAnyTransition(Fade fade)
{
object trans = fade.Transition;
if (trans != null)
{
fade.RemoveTransition();
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
@jetdv Please sir, if you can help, I watched these tutorials;
How to get the list of effects: How to add an effect and pick a preset: Add Generated Media to the timeline:
But, I can't make it work picking the preset of the Media Generator as the same as an effect.
When i use the script the Media generator (legacy text) is added in the timeline but the Preset is not.
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using System.Windows.Forms;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
Track myTrack = myVegas.Project.Tracks[0];
string genUID = "{0FE8789D-0C47-442A-AFB0-0DAF97669317}";
int presetCount = 3;
PlugInNode plugIn = null;
plugIn = myVegas.Generators.GetChildByUniqueID(genUID);
Media media = new Media(plugIn);
MediaStream stream = media.Streams.GetItemByMediaType(MediaType.Video, 0);
VideoEvent newEvent = new VideoEvent(myVegas.Transport.CursorPosition, Timecode.FromSeconds(10));
myTrack.Events.Add(newEvent);
Take take = new Take(stream);
newEvent.Takes.Add(take);
Effect effect = new Effect(plugIn);
newEvent.Effects.Add(effect);
effect.Preset = effect.Presets[presetCount].Name;
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
The mistakes are in these lines?;
Effect effect = new Effect(plugIn);
newEvent.Effects.Add(effect);
effect.Preset = effect.Presets[presetCount].Name;
The script is about insert the media generator legacy text with the preset soft shadow or any other preset.
foreach (Track myTrack in myVegas.Project.Tracks)
{
foreach (TrackEvent vEvnt in myTrack.Events)
{
if (vEvnt.Selected)
{
MessageBox.Show("AAA cugo");
vEvnt.FadeIn.RemoveTransition();
myVegas.UpdateUI();
MessageBox.Show("AAAvvvvv");
vEvnt.FadeOut.RemoveTransition();
myVegas.UpdateUI();
MessageBox.Show("AAAcccc");
}
}
}
For example. I have one video event. This event has FadeIn and FadeOut transitions. I want them to remove, but unfortunately I am not able to remove them using above script. Is it something wrong with the script or maybe it is Vegas Pro 21 & Vegas Pro 22 bug?
It doesn't work also for VideoEvent. Initially I tried to launch your code from 8/4/2024 1:02 AM, but unfortunately it doesn't work for Vegas Pro 21 & 22.
Can you check it if this problem occurs on your PC, maybe it is only my PC issue?
@marcinzm A while ago, I wrote this code to delete fade in / out and CrossFade. It was possible thanks to the amazing lessons from @jetdv YouTube Channel. It is not perfect, but it works good. @jetdv Thanks again, Sir.
void RemoveFadeCrossFade(Vegas vegas)
{
myVegas = vegas;
List<TrackEvent> selectedEvents = new List<TrackEvent>();
// Collect all selected events in the proper sequence
foreach (Track track in myVegas.Project.Tracks)
{
if (track.IsAudio() || track.IsVideo())
{
foreach (TrackEvent trackEvent in track.Events)
{
if (trackEvent.Selected)
{
// Do not add the audio event if it's grouped with a video event
if (trackEvent.Track.IsAudio() && IsPartOfGroupedVideo(trackEvent))
{
continue; // Skip adding the grouped audio event
}
selectedEvents.Add(trackEvent);
}
}
}
}
// Handle crossfade and fade removals for video and audio events
for (int i = 0; i < selectedEvents.Count; i++)
{
TrackEvent currentEvent = selectedEvents[i];
TrackEvent nextEvent = i + 1 < selectedEvents.Count ? selectedEvents[i + 1] : null;
// Remove fades for the current event
RemoveFades(currentEvent);
if (nextEvent != null)
{
// If the events are grouped, do not move the audio event
if (!IsGroupedAndAudio(currentEvent, nextEvent))
{
// If there's overlap, adjust the next event's start time without shifting its position
if (nextEvent.Start < currentEvent.End)
{
Timecode overlap = currentEvent.End - nextEvent.Start;
nextEvent.Start += overlap; // Adjust start without affecting position sequence
}
// Remove fades from the next event as well
RemoveFades(nextEvent);
}
}
}
// Call ProcessAudioEvents to handle audio-specific logic after the general fade removal
ProcessAudioEvents();
}
private void RemoveFades(TrackEvent trackEvent)
{
// Remove fade-in
if (trackEvent.FadeIn.Length > Timecode.FromMilliseconds(0))
{
trackEvent.FadeIn.Length = Timecode.FromMilliseconds(0);
}
// Remove fade-out
if (trackEvent.FadeOut.Length > Timecode.FromMilliseconds(0))
{
trackEvent.FadeOut.Length = Timecode.FromMilliseconds(0);
}
}
private bool IsGroupedAndAudio(TrackEvent event1, TrackEvent event2)
{
// If both events are grouped and one is an audio event, return true
if (event1.Group != null && event1.Group == event2.Group)
{
if (event1.Track.IsAudio() || event2.Track.IsAudio())
{
return true; // Audio event, so we do not want to move it
}
}
return false;
}
private bool IsPartOfGroupedVideo(TrackEvent audioEvent)
{
// Check if the audio event is grouped with a video event
if (audioEvent.Group != null)
{
foreach (Track track in myVegas.Project.Tracks)
{
foreach (TrackEvent trackEvent in track.Events)
{
if (trackEvent.Group == audioEvent.Group && trackEvent.Track.IsVideo())
{
return true; // Audio event is grouped with a video event
}
}
}
}
return false;
}
// New method to handle audio events specifically
public void ProcessAudioEvents()
{
List<TrackEvent> selectedAudioEvents = new List<TrackEvent>();
// Collect all selected audio events
foreach (Track track in myVegas.Project.Tracks)
{
if (track.IsAudio())
{
foreach (TrackEvent trackEvent in track.Events)
{
if (trackEvent.Selected)
{
selectedAudioEvents.Add(trackEvent);
}
}
}
}
// Now handle the crossfade and fade removals for audio events
for (int i = 0; i < selectedAudioEvents.Count; i++)
{
TrackEvent currentEvent = selectedAudioEvents[i];
TrackEvent nextEvent = i + 1 < selectedAudioEvents.Count ? selectedAudioEvents[i + 1] : null;
// Remove fades for the current audio event
RemoveFades(currentEvent);
if (nextEvent != null)
{
// Adjust the next audio event if there's overlap
if (nextEvent.Start < currentEvent.End)
{
Timecode overlap = currentEvent.End - nextEvent.Start;
nextEvent.Start += overlap; // Adjust start time of the next event
}
// Remove fades from the next audio event
RemoveFades(nextEvent);
}
}
}
You can create a "fade in" or "fade out" and not have a transition on it.
Technically, you can have a transition with no fade in/out (you just won't see it.)
They work together but they are two different things. So, yes, it was initially removing the "Transition" but was not removing the "fade out". To remove a "fade out", you just set its length to "zero."
@Steve_Rhoden Do you mean, a script only to remove the audio effects from selected audio events? This script below does that.
using System;
using System.Drawing;
using System.Windows.Forms;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
try
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
foreach (AudioEvent aEvnt in myTrack.Events)
{
if (aEvnt.Selected)
{
aEvnt.Effects.Clear();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error");
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
}
@jetdv Yes, Sir, I understood that, thanks. Maybe, @Steve_Rhoden needs a script that removes fade in, fade out, crossfades and audio effects from selected events.
@jetdv Thanks for the input... Currently i use the remove transitions and the remove video effects scripts feature from Vegasaur, but there is no remove audio effects, so i wanted a script to complete the family.