Create a script that removes transitions?

Thiago_Sase wrote on 8/3/2024, 3:58 PM

@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.

 

Comments

jetdv wrote on 8/3/2024, 6:02 PM

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

 

Thiago_Sase wrote on 8/5/2024, 8:30 AM

@jetdv Thank you very much sir! It worked.

jetdv wrote on 8/5/2024, 8:42 PM

@Thiago_Sase, I later tested it and then created a tutorial based on it. It will be coming up in a few weeks.

Thiago_Sase wrote on 8/5/2024, 9:01 PM

@jetdv Very good news! Thank you.

Thiago_Sase wrote on 8/6/2024, 8:02 PM

@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.

jetdv wrote on 8/6/2024, 8:12 PM

Try this:
 

            string genUID = "{Svfx:com.vegascreativesoftware:titlesandtext}"; //Magix Titles & Text
            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(15));
            Mtrack.Events.Add(newEvent);
            Take take = new Take(stream);
            newEvent.Takes.Add(take);

            Effect gEffect = newEvent.ActiveTake.Media.Generator;
            gEffect.Preset = gEffect.Presets[presetCount]

 

Thiago_Sase wrote on 8/6/2024, 8:34 PM

@jetdv This line;

  gEffect.Preset = gEffect.Presets[presetCount];

Gives the error: Cannot implicitly convert type 'ScriptPortal.Vegas.EffectPreset' to 'string'.

jetdv wrote on 8/7/2024, 8:01 AM

Sorry, left off the .Name...

            Effect gEffect = newEvent.ActiveTake.Media.Generator;
            gEffect.Preset = gEffect.Presets[presetCount].Name;

 

Thiago_Sase wrote on 8/7/2024, 8:11 AM

@jetdv It worked Sir. Thank you very much!

marcinzm wrote on 10/25/2024, 8:33 AM
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?

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

jetdv wrote on 10/25/2024, 8:41 AM

@marcinzm you need to change this line:

foreach (TrackEvent vEvnt in myTrack.Events)

to:

foreach (VideoEvent vEvnt in myTrack.Events)

You have to be looking at "VideoEvent"s to be able to remove the transitions. It does not work with "TrackEvent" or "AudioEvent".

marcinzm wrote on 10/25/2024, 9:08 AM

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?

Last changed by marcinzm on 10/25/2024, 9:20 AM, changed a total of 1 times.

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

jetdv wrote on 10/25/2024, 10:10 AM

@marcinzm Yes, this works just fine (with TrackEvent, VideoEvent, or AudioEvent - I just double-checked) in VEGAS Pro 22:

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    foreach (TrackEvent vEvnt in myTrack.Events)
                    {
                        if (vEvnt.Selected)
                        {
                            vEvnt.FadeIn.RemoveTransition();
                            myVegas.UpdateUI(); //not really needed
                            vEvnt.FadeOut.RemoveTransition();
                            myVegas.UpdateUI(); //not really needed
                        }
                    }
                }
            }
        }

I had an event fade in and added a transition on the event fade out and the transition was removed.

Now, it won't remove a CROSSFADE. To do that you'd need to add:

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    foreach (TrackEvent vEvnt in myTrack.Events)
                    {
                        if (vEvnt.Selected)
                        {
                            vEvnt.FadeIn.RemoveTransition();
                            vEvnt.FadeIn.Length = Timecode.FromFrames(0);

                            vEvnt.FadeOut.RemoveTransition();
                            vEvnt.FadeOut.Length = Timecode.FromFrames(0);
                        }
                    }
                }
            }
        }

So if you want to remove crossfades on audio too, just remove my check for "if (myTrack.IsVideo())".

Thiago_Sase wrote on 10/25/2024, 12:42 PM

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


 

marcinzm wrote on 10/25/2024, 3:18 PM

Thank you all for your codes.

@jetdv It is very weird that this single line

Evnt.FadeIn.RemoveTransition();

doesn't work itself.

it is every weird too that this line needs to be added:

vEvnt.FadeIn.Length = Timecode.FromFrames(0);

It is in my opinion illogical, but I have just checked that it works. Very very weird.

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

jetdv wrote on 10/25/2024, 5:07 PM

@marcinzm, they're TWO DIFFERENT THINGS.

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 wrote on 11/2/2024, 12:45 PM

Tell me something gentlemen, can a script similar to the aboves be written to remove audio effects from selected audio events?

A script like that would also compliment these.

jetdv wrote on 11/2/2024, 6:34 PM

@Steve_Rhoden Audio Events don't have transitions. You can certainly change the fade in/out times, though.

Thiago_Sase wrote on 11/2/2024, 6:45 PM

@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 wrote on 11/2/2024, 6:50 PM

@Thiago_Sase, this post is about transitions... Audio doesn't have transitions. Just fade in, fade out, and crossfades.

Thiago_Sase wrote on 11/2/2024, 6:56 PM

@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.

Steve_Rhoden wrote on 11/2/2024, 11:46 PM

Thanks @Thiago_Sase, that's exactly what i meant. Want it to remove audio effects on selected audio events.

Gonna give your script a try.....

Steve_Rhoden wrote on 11/3/2024, 3:20 AM

@Thiago_Sase That script works great. It's what i was looking for. Thanks.

Steve_Rhoden wrote on 11/3/2024, 3:36 AM

@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.