Is this a Bug? Script that launches adjustment event on Vegas Pro 22.

Thiago_Sase wrote on 8/5/2024, 1:08 PM

Is this a Bug? The script bellow works on Vegas Pro 21 and does not work on Vegas Pro 22. But, if i add manually, menu, insert, then the adjustment event works properly on Vegas Pro 22.

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() && myTrack.Selected)
                {
                    VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromSeconds(5), "Adjustment Event");
                    myTrack.Events.Add(vaEvent);
                }
            }

            

        }

    }
}


public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

I also did a video explaining the situation;


 

Comments

zzzzzz9125 wrote on 8/5/2024, 7:52 PM

@Thiago_Sase The same problem is found here.

Just tried decompiling and comparing the script dlls of 21 and 22, and found that the adjustment events in 22 have the following public properties and methods:

double PixelAspectRatio
int FrameWidth
int FrameHeight

void UpdateDimensions(int width, int height, double pixelAspect)

For example, the following code is valid and can solve the problem in 22:

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() && myTrack.Selected)
                {
                    VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromSeconds(5), "Adjustment Event");
                    myTrack.Events.Add(vaEvent);
                    ProjectVideoProperties pV = myVegas.Project.Video;
                    vaEvent.UpdateDimensions(pV.Width, pV.Height, pV.PixelAspectRatio);
                }
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

But in 21, it's invalid because no such method or property exists.

@VEGASDerek I think it's a compatibility issue, please fix it. Otherwise the user would have to write two different script contents for 21 and 22.

Last changed by zzzzzz9125 on 8/5/2024, 7:54 PM, changed a total of 1 times.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Jack S wrote on 8/6/2024, 6:46 AM

@Thiago_Sase That's strange. I used your script to add an adjustment event into VP21 and I get the same result as with VP22, a blank Pan/Crop window. So, as far as I can see, the problem isn't unique to VP22.
Maybe @jetdv can shed some light on the issue.

I'm glad you raised the issue because I have an application extension that has a tool for adding adjustment events and I didn't know about this problem (it's virtually impossible to test for everything).

@zzzzzz9125 Can you elaborate on your solution, particularly the method

void UpdateDimensions(int width, int height, double pixelAspect)

You don't include a body for this method and I've been trying to work out what I should put in the body.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

zzzzzz9125 wrote on 8/6/2024, 7:34 AM

@Jack S Here's the decompiled code I got via Visual Studio 2022, which is present in VP22 but not in VP21:

    public double PixelAspectRatio
    {
        get
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            return pixelAspect;
        }
        set
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            pixelAspect = value;
            myCOM.SetAdjEventDimensions(myTrackID, myEventID, width, height, pixelAspect);
        }
    }

    public int FrameWidth
    {
        get
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            return width;
        }
        set
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            width = value;
            myCOM.SetAdjEventDimensions(myTrackID, myEventID, width, height, pixelAspect);
        }
    }

    public int FrameHeight
    {
        get
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            return height;
        }
        set
        {
            Validate();
            double pixelAspect = 0.0;
            int width = 0;
            int height = 0;
            myCOM.GetAdjEventDimensions(myTrackID, myEventID, out width, out height, out pixelAspect);
            height = value;
            myCOM.SetAdjEventDimensions(myTrackID, myEventID, width, height, pixelAspect);
        }
    }



    public void UpdateDimensions(int width, int height, double pixelAspect)
    {
        Validate();
        myCOM.SetAdjEventDimensions(myTrackID, myEventID, width, height, pixelAspect);
    }

 

That said, you have two ways to set its width and height:

vaEvent.UpdateDimensions(width, height, pixelAspectRatio);

or:

vaEvent.FrameWidth = width;
vaEvent.FrameHeight = height;
vaEvent.PixelAspectRatio = pixelAspectRatio;

 

If I write them both into my code, it's:

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() && myTrack.Selected)
                {
                    VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromSeconds(5), "Adjustment Event");
                    myTrack.Events.Add(vaEvent);
                    ProjectVideoProperties pV = myVegas.Project.Video;
                    vaEvent.UpdateDimensions(pV.Width, pV.Height, pV.PixelAspectRatio);
                    vaEvent.FrameWidth = pV.Width;
                    vaEvent.FrameHeight = pV.Height;
                    vaEvent.PixelAspectRatio = pV.PixelAspectRatio;
                }
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

Either of these two works for me in VP22.

However, for VP21, the same code CAN'T be used, or you will definitely get an error.

 

Update: @Thiago_Sase's code works well here in my 21 build 208, I can't reproduct @Jack S's problem with VP21. Maybe it has something to do with the build number?

Last changed by zzzzzz9125 on 8/6/2024, 7:55 AM, changed a total of 7 times.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Thiago_Sase wrote on 8/6/2024, 10:04 AM

@zzzzzz9125 You are a Genius! This works perfectly on vegas pro 22 (build 93).

I'm studying, practising and trying to write scripts for Vegas making combinations with the Adjustment Event. So this function is quite important to me at the moment. I'm learning a lot studying yours and @jetdv posts here in the forum and watching @jetdv Tutorials on his channel on youtube as well. You guys are the Professors of scripting for Vegas Pro.

Thank you very much for both of you and others guys of this forum that have the knowledge of scripting for Vegas and always are available for helping.

Thiago_Sase wrote on 8/6/2024, 10:13 AM

@Jack S The original version of the script was written by @jetdv. It works for me on Vegas Pro 21 (Build 315) but, even on 21 has a lot of bugs, specially using third parties plugins as like Boris FX and Sapphire. And constantly crashes. But now with the update version of the script written by @zzzzzz9125 everything involving Adjustment Event is working very well. So far so good. But, as @zzzzzz9125 mentioned, the updated script only works on Vegas Pro 22.

Jack S wrote on 8/6/2024, 12:00 PM

@zzzzzz9125 Thanks for that. I'll digest it and modify my script to suit. When I tried my tool using VP21 I got the same result as in VP22 (blank Pan/Crop preview), so the mod should work for both versions. I'll let you know either way.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 8/6/2024, 6:01 PM

@zzzzzz9125 OK, I'm stumped. Where is the Class myCOM declared? I can't see it in the code anywhere, and I can't complete the UpdateDimensions method without it being declared somewhere.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

zzzzzz9125 wrote on 8/6/2024, 8:11 PM

OK, I'm stumped. Where is the Class myCOM declared? I can't see it in the code anywhere, and I can't complete the UpdateDimensions method without it being declared somewhere.

@Jack S It's the internal implementation of VEGAS Script API in VP22, and you can't do the same thing by manually adding code to your script in VP21. Since the OP's problem is specific to VP22 and I also found it in VP22, I solved this problem by the method in VP22. For VP21, I haven't found this issue yet, and I'm not sure how to fix it.

Perhaps you should provide your build number? I'm using 21 build 208, @Thiago_Sase is using 21 build 315, we have no problem with either. Or, you can share a project that went wrong, it may have something to do with your project properties. The problem is, I can't see your problem, so we're not on the same channel.

Last changed by zzzzzz9125 on 8/6/2024, 8:12 PM, changed a total of 1 times.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Thiago_Sase wrote on 8/6/2024, 9:16 PM

@zzzzzz9125 @Jack S There was a mistake of mine, sorry. When i was testing the original script was on Vegas Pro 21 (build 208), That's why it worked on 21. I tested on another versions of 21 and Here's the update;

Original Script will work;

Vegas Pro 21 (build 108) - It works.
Vegas Pro 21 (build 187) - It works.
Vegas Pro 21 (build 208) - It works.
Vegas Pro 21 (build 300) - It does not work.
Vegas Pro 21 (build 314) - It does not work.
Vegas Pro 21 (build 315) - It does not work.

​​​​​​​Vegas Pro 22 (build 93) - It does not work.

The updated version of the script by @zzzzzz9125 will work;

Vegas Pro 22 (build 93) - It works.

 

 

Last changed by Thiago_Sase on 8/6/2024, 9:18 PM, changed a total of 1 times.

OS: Windows 10 22H2
CPU: Intel Core I7 12700
MEMORY: 32GB DDR4 3200MHz
GHAPHIC CARD: RTX 3060 8GB
HARD DRIVES: SSD for System and M.2 for Media Files

zzzzzz9125 wrote on 8/6/2024, 10:02 PM

There was a mistake of mine, sorry. When i was testing the original script was on Vegas Pro 21 (build 208), That's why it worked on 21. I tested on another versions of 21 and Here's the update;

Original Script will work;

Vegas Pro 21 (build 108) - It works.
Vegas Pro 21 (build 187) - It works.
Vegas Pro 21 (build 208) - It works.
Vegas Pro 21 (build 300) - It does not work.
Vegas Pro 21 (build 314) - It does not work.
Vegas Pro 21 (build 315) - It does not work.

Vegas Pro 22 (build 93) - It does not work.

The updated version of the script by @zzzzzz9125 will work;

Vegas Pro 22 (build 93) - It works.

@Thiago_Sase You're right. I just upgraded to 315 and observed the same problem, and I don't seem to have found any viable solution to this problem.

Trying to search on this forum, we're able to get at least two similar threads:
https://www.vegascreativesoftware.info/us/forum/vegas-pro-21-build-300-adjustment-event-error--145465/
https://www.vegascreativesoftware.info/us/forum/copy-pasting-adjustment-event-between-projects-breaks-effects--145810/

And in VP22 Update Log, there're such two lines:

  • Fixes improve the behavior of Adjustment Events
  • Copy and paste of an Adjustment Event from one instance of VEGAS to another now works as expected

It appears that the issue starts from 21 build 300 and is marked as "solved" in 22.

@Jack S In this case, you can only:

  1. Downgrade to 21 build 208, but the projects you created with 315 CANNOT be opened with 208.
  2. Pay to upgrade to 22.

 

@VEGASDerek In this response, you said:

We have a fix for this and it is scheduled to be part of the patch that we are working on.

May I ask, is build 315 the final version of 21, or will there be additional fixes? This question is important for users who only have 21.

Last changed by zzzzzz9125 on 8/6/2024, 10:20 PM, changed a total of 5 times.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Jack S wrote on 8/7/2024, 5:10 AM

@Thiago_Sase 

Vegas Pro 21 (build 315) - It does not work.

That explains it. That's why it didn't work for me in VP21. I'm on build 315.

@zzzzzz9125

It's the internal implementation of VEGAS Script API in VP22,

My problem is, my code resides in a module for my application extension, so it relies on the ScriptPortal.Vegas.dll defined in Visual Studio. I've pointed mine to the one in the VP22 folder but I still can't get the myCOM statement to be recognised. I can't find any reference to a COM class in the API so it must have been updated. I'll have to check to see if the link to the API has been updated. If it has, I may be able to find what this class is. I'll let you know.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 8/7/2024, 8:48 AM

@zzzzzz9125 Got it, finally. This is the modified method in my module for adding an adjustment event at the cursor position. The module is part of my application extension.

        private void A_Event()
        {
            ProjectVideoProperties pV = myVegas.Project.Video;              //Create a ProjectVideoProperties class and name it pV
                                                                            //This is a prerequisite for a VP22 adjustment event

            CanRipple = true;                                               //Assume that it's OK to ripple
            int TrkCount = myVegas.Project.Tracks.Count;
            if (TrkCount == 0)
            {
                MessageBox.Show("There are no tracks in the project", "Invalid action", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            bool TrkSel = false;                                                                        //Initialise the Track Selected flag.

            foreach (Track myTrack in myVegas.Project.Tracks)                                           //Scan through all the tracks.
            {
                if (myTrack.IsVideo() && myTrack.Selected)                                              //If it's a video track and is selected ...
                {
                    TrkSel = true;                                                                      //... set the Track Selected flag to true.
                    if (radBtnSecs.Checked)                                                             //If the time selection is in seconds ...
                    {                                                                                   //... add the adjustment event
                        VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromSeconds((double)aEventDur), "Adjustment Event");
                        myTrack.Events.Add(vaEvent);

                        vaEvent.UpdateDimensions(pV.Width, pV.Height, pV.PixelAspectRatio);             //Get the project's properties ...
                    }                                                                                   //... and update the adjustment event
                    else                                                                                //Time selection must be in frames
                    {                                                                                   //... add the adjustment event
                        VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromFrames((long)aEventDur), "Adjustment Event");
                        myTrack.Events.Add(vaEvent);

                        vaEvent.UpdateDimensions(pV.Width, pV.Height, pV.PixelAspectRatio);             //Get the project's properties ...
                    }                                                                                   //... and update the adjustment event
                }
            }
            if (!TrkSel)                                                                                //If a video track is not selected ...
            {
                MessageBox.Show("The track selected isn't a video track", "Invalid track", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);    //... inform the user.
                CanRipple = false;                                               //Prevent rippling
            }
        }

        private void UpdateDimensions(int width, int height, double pixelAspect)
        {
            width = myVegas.Project.Video.Width;
            height = myVegas.Project.Video.Height;
            pixelAspect = myVegas.Project.Video.PixelAspectRatio;
        }

Thank you for pointing me in the right direction.

As you commented, I've tried the application in VP21 and VP crashes when I try to add the event. I already have a test for VP21 and above in the module. I'll just have to alter the test to make it VP22 and above. Until of course someone comes up with a solution.

Last changed by Jack S on 8/7/2024, 8:49 AM, changed a total of 1 times.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

zzzzzz9125 wrote on 8/7/2024, 9:46 AM

@Jack S I think you misread me? The method you wrote is useless and not actually called:

        private void UpdateDimensions(int width, int height, double pixelAspect)
        {
            width = myVegas.Project.Video.Width;
            height = myVegas.Project.Video.Height;
            pixelAspect = myVegas.Project.Video.PixelAspectRatio;
        }

UpdateDimensions() method is obtained by decompiling, instead of adding it manually.

If you delete these lines and your compiler (Visual Studio for example) says there's no such method, you are not using ScriptPortal.Vegas.dll of VP22, but VP21. Replace it with the .dll of VP22 in the references. This way, your compiler will not report errors.

After making sure you're using ScriptPortal.Vegas.dll of VP22, next comes the use of decompilers. Assuming your compiler is Visual Studio 2022, you can just hold down Ctrl and click here:

Now we have the decompiled code.

Why decompile? Because this is a new API content that has not yet been documented in the VEGAS Script API documentation. We had to decompile to know that we could use it this way.

With this information, we can get to what I talked about at the beginning:

The same problem is found here.

Just tried decompiling and comparing the script dlls of 21 and 22, and found that the adjustment events in 22 have the following public properties and methods:

double PixelAspectRatio
int FrameWidth
int FrameHeight

void UpdateDimensions(int width, int height, double pixelAspect)

For example, the following code is valid and can solve the problem in 22:

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() && myTrack.Selected)
                {
                    VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, Timecode.FromSeconds(5), "Adjustment Event");
                    myTrack.Events.Add(vaEvent);
                    ProjectVideoProperties pV = myVegas.Project.Video;
                    vaEvent.UpdateDimensions(pV.Width, pV.Height, pV.PixelAspectRatio);
                }
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

But in 21, it's invalid because no such method or property exists.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Jack S wrote on 8/7/2024, 10:20 AM

@zzzzzz9125 Gotcha. So UpdateDimensions is part of the VideoAdjustmentEvent class. I didn't know that. That's why I couldn't find it in the API (which ought to be updated).
I was using VP21 scriptportal but I changed it to VP22 scriptportal,

Anyway, I deleted the UpdateDimensions method and it still works.

I didn't know about the decompile option. That's good to know, thanks a lot.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

zzzzzz9125 wrote on 8/7/2024, 10:22 AM

As you commented, I've tried the application in VP21 and VP crashes when I try to add the event. I already have a test for VP21 and above in the module. I'll just have to alter the test to make it VP22 and above. Until of course someone comes up with a solution.

@Jack S And then there's this question. VP21 crashes because you tried to call method that doesn't belong to it. A possible solution:

        private void A_Event()
        {
            int versionNumber = System.Diagnostics.FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileMajorPart; // Get VEGAS Pro's major version number.
            CanRipple = true;                                               //Assume that it's OK to ripple
            int TrkCount = myVegas.Project.Tracks.Count;
            if (TrkCount == 0)
            {
                MessageBox.Show("There are no tracks in the project", "Invalid action", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            bool TrkSel = false;                                                                        //Initialise the Track Selected flag.

            foreach (Track myTrack in myVegas.Project.Tracks)                                           //Scan through all the tracks.
            {
                if (myTrack.IsVideo() && myTrack.Selected)                                              //If it's a video track and is selected ...
                {
                    TrkSel = true;                                                                      //... set the Track Selected flag to true.
                    VideoAdjustmentEvent vaEvent = new VideoAdjustmentEvent(myVegas.Project, myVegas.Transport.CursorPosition, radBtnSecs.Checked ? Timecode.FromSeconds((double)aEventDur) : Timecode.FromFrames((long)aEventDur), "Adjustment Event");
                    myTrack.Events.Add(vaEvent);
                    if (versionNumber > 21) // Avoid throwing errors in unsuitable versions.
                    {
                        UpdateAdjEvents(vaEvent, myVegas.Project);
                    }
                }
            }
            if (!TrkSel)                                                                                //If a video track is not selected ...
            {
                MessageBox.Show("The track selected isn't a video track", "Invalid track", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);    //... inform the user.
                CanRipple = false;                                               //Prevent rippling
            }
        }

        private void UpdateAdjEvents(VideoAdjustmentEvent evnt, Project proj)
        {
            evnt.UpdateDimensions(proj.Video.Width, proj.Video.Height, proj.Video.PixelAspectRatio);
        }

As you can see, I took the UpdateDimensions() method out and put it in a separate self-written method. Before the main method calls this method, I make a judgment about the version number in advance, and if the version number doesn't fit, skip it so it won't throw an error in 21.

I optimized the content of your code, but since I don't have the full code, I can't test it. You can try it out and give feedback.

 

However, as @Thiago_Sase tested, such code can't generate the correct adjustment events in 21 build 300-315, but it should work for both 21 build 108-208 and 22. This problem should be solved by the VEGAS developers (@VEGASDerek), not the users who write scripts like us.

Last changed by zzzzzz9125 on 8/7/2024, 10:34 AM, changed a total of 3 times.

Using VEGAS Pro 22 build 122 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

Jack S wrote on 8/7/2024, 10:38 AM

@zzzzzz9125 I already had a bit of code to prevent adjustment event addition in versions prior to VP21. It's a bit fiddly to test for build numbers as well, so I have to accept that users of VP21 won't be able to use my module for adding an adjustment event, even though they can add it manually with the Insert option.
I've had past experiences with code crashes where I've parsed a string into an integer when the string has been null so I added a bit more code to test for that. This is the method called when the button is clicked.

        private void aEventFixed_Click(object sender, EventArgs e)
        {
            string VerNo = myVegas.Version;                         //Obtain the version of Vegas Pro being used.
            string VPVsn = VerNo.Substring(8, 2);                   //Extract the version number
            if (string.IsNullOrEmpty(VPVsn))                       //VPVsn should never be empty. But if it is, inform.
            {
                MessageBox.Show("Vegas Pro version number returned a null string", "Invalid version number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;                                             //Can't go any further
            }
            int IVPVsn = int.Parse(VPVsn);                          //OK to convert it into an integer.
            if (IVPVsn < 22)                                        //Is the version number less than 22 (Although VP21 is the first version to include the adjustment event function ...
            {                                                       //... VP21 build 300 and later has a problem with the Pan/Crop preview window
                MessageBox.Show(OptionNotAvail, "Vegas Pro version", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);   //Yes, inform the user.
            }
            else                                                                                //Otherwise, proceed as normal.
            {
                using (UndoBlock undo = new UndoBlock("Insert Adjustment Event"))               //Enable undo.
                {
                    fxdaEvntApp();                                                              //Call the method to apply the event
                }
                SetFocus(new HandleRef(null, myVegas.MainWindow.Handle));                       //Enable the use of Ctrl+Z for undo.
            }
        }

I like your method of obtaining the version number as an integer. Much more elegant than mine, and it negates the risk of parsing a null string. I'll have to use it. Thanks again for the valuable information.

Last changed by Jack S on 8/7/2024, 10:41 AM, changed a total of 1 times.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 8/7/2024, 10:57 AM

@zzzzzz9125 Your version of obtaining the version number implemented, thanks. It's gone into my document containing scripting and scriptportal information.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE