Can't set frame data from custom command

Latch wrote on 1/14/2023, 3:42 PM

Visual Studio 2022, Vegas Pro 18.0

So I'm running the following code in a ""custom command" project.

        public static void AdjustBoundsTo1080p(VideoEvent targetEvent)
        {
            if(targetEvent != null)
            {
                Debug.WriteLine("Target Event not null");
            }
            if (targetEvent.VideoMotion.Keyframes != null)
            {
                Debug.WriteLine("keyframes not null");
            }
            if (targetEvent.VideoMotion.Keyframes[0] != null)
            {
                Debug.WriteLine("keyframes 0 index not null");
            }

            VideoMotionKeyframes currentKeyframes = targetEvent.VideoMotion.Keyframes;
            VideoMotionKeyframe newSingleFrame = currentKeyframes[0];

            Debug.WriteLine("About to check count");
            Debug.WriteLine("Frame count is " + currentKeyframes.Count);
            Debug.WriteLine("After count report");

            Debug.WriteLine("Changing the bounds of " + targetEvent.MediaType.ToString());
            Debug.WriteLine("video events starts at " + targetEvent.Start);

            VideoMotionBounds bounds = newSingleFrame.Bounds;

            if (bounds == null)
            {
                Debug.WriteLine("bounds is null");
            }

            string debugOutput = "Before change\n";
            debugOutput += "Upper Left: " + bounds.TopLeft.X + "," + bounds.TopLeft.Y + "\n";
            debugOutput += "Upper Right: " + bounds.TopRight.X + "," + bounds.TopRight.Y + "\n";
            debugOutput += "Bottom Left: " + bounds.BottomLeft.X + "," + bounds.BottomLeft.Y + "\n";
            debugOutput += "Bottom Right: " + bounds.BottomRight.X + "," + bounds.BottomRight.Y + "\n";
            Debug.WriteLine(debugOutput);

            bounds.TopRight.Y = 0;
            bounds.TopLeft.Y = 0;
            bounds.BottomRight.Y = 1080;
            bounds.BottomLeft.Y = 1080;

            bounds.TopRight.X = 1920;
            bounds.TopLeft.X = 0;
            bounds.BottomRight.X = 1920;
            bounds.BottomLeft.X = 0;

            Debug.WriteLine("About to set bounds");
            currentKeyframes[0].Bounds = bounds;
            Debug.WriteLine("After to setting bounds");
        }

and the output I get is

Target Event not null
keyframes not null
keyframes 0 index not null
About to check count
Frame count is 1
After count report
Changing the bounds of Video
video events starts at 00:00:56.04
Before change
Upper Left: 320,180
Upper Right: 1600,180
Bottom Left: 320,900
Bottom Right: 1600,900

About to set bounds
Exception thrown: 'System.ApplicationException' in ScriptPortal.Vegas.dll

I've also tried adding more keyframes but when I check the count it also throws an exception.
 

VideoMotionKeyframe nkf = new VideoMotionKeyframe(Timecode.FromSeconds(1));
currentKeyframes.Add(nkf);
VideoMotionKeyframe nkf2 = new VideoMotionKeyframe(Timecode.FromSeconds(2));
currentKeyframes.Add(nkf2);
// Exception just by checking the count 
Debug.WriteLine("Frame count is " + currentKeyframes.Count);


But here is the thing, when I go to my other project. The one that makes one off DLL's it works. I don't understand the difference between the projects. So in the end what I'm asking is there anything that I forgot to setup in a custom command project to explain this behavior?

Comments

jetdv wrote on 1/14/2023, 4:43 PM

Try changing:

            bounds.TopRight.Y = 0;
            bounds.TopLeft.Y = 0;
            bounds.BottomRight.Y = 1080;
            bounds.BottomLeft.Y = 1080;
            bounds.TopRight.X = 1920;
            bounds.TopLeft.X = 0;
            bounds.BottomRight.X = 1920;
            bounds.BottomLeft.X = 0;

to:

             bounds.TopRight.Y = 0f;
             bounds.TopLeft.Y = 0f;
             bounds.BottomRight.Y = 1080f;
             bounds.BottomLeft.Y = 1080f;
             bounds.TopRight.X = 1920f;
             bounds.TopLeft.X = 0f;
             bounds.BottomRight.X = 1920f;
             bounds.BottomLeft.X = 0f;

 

Latch wrote on 1/14/2023, 7:30 PM

Unfortunately that didn't work but I did realize something.

I'm going to strip down the CC project to just it's base components and review your video again. I'm sure there is something that I missed. What confused me when I posted this was the fact that I could edit the projects text video events with the CC. But I realized because I wanted to have it trigger from a hotkey I just have the CC save data to a file and then a separate DLL just reads from the file and makes the changes. So I never had the CC project working apparently. Will report back if find the line I messed up.