ERROR: Failed to set bounds. One or more vertices invalid.

RedyM wrote on 12/3/2022, 7:48 PM

Hey, I'm getting this error when trying to set the bounds on a keyframe: "Failed to set bounds. One or more vertices invalid."

As you can see I'm not even editing the bounds and I'm still getting this error:

foreach (Track track in myVegas.Project.Tracks)
            {
                if (track.IsVideo())
                {
                    foreach (TrackEvent trackEvent in track.Events)
                    {
                        VideoEvent videoEvent = (VideoEvent)trackEvent;
                        VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
                        VideoMotionKeyframe keyframe = videoKeyframes[0];
                        VideoMotionBounds bounds = keyframe.Bounds;

                        keyframe.Bounds = bounds;
                    }
                }
            }

I also tried to change the bounds like so:

foreach (Track track in myVegas.Project.Tracks)
            {
                if (track.IsVideo())
                {
                    foreach (TrackEvent trackEvent in track.Events)
                    {
                        VideoEvent videoEvent = (VideoEvent)trackEvent;
                        VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
                        VideoMotionKeyframe keyframe = videoKeyframes[0];
                        VideoMotionBounds bounds = keyframe.Bounds;

                        bounds.TopLeft = new VideoMotionVertex(0, 0);
                        bounds.TopRight = new VideoMotionVertex(100, 0);
                        bounds.BottomLeft = new VideoMotionVertex(0, 100);
                        bounds.BottomRight = new VideoMotionVertex(100, 100);

                        keyframe.Bounds = bounds;
                    }
                }
            }

but it doesn't work either. The error occurs at the following line: "keyframe.Bounds = bounds;"

Anyone knows why?

Comments

jetdv wrote on 12/4/2022, 7:31 AM

I just ran your first block of code on my system (with multiple video tracks and video events) on my system and this worked fine:

foreach (Track track in myVegas.Project.Tracks)
{
    if (track.IsVideo())
    {
        foreach (TrackEvent trackEvent in track.Events)
        {
            VideoEvent videoEvent = (VideoEvent)trackEvent;
            VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
            VideoMotionKeyframe keyframe = videoKeyframes[0];
            VideoMotionBounds bounds = keyframe.Bounds;

            keyframe.Bounds = bounds;
        }
    }
}

I ran my test on VEGAS Pro 20. What version of VEGAS are you using? Do you happen to have an "empty event" on the timeline?

 

RedyM wrote on 12/4/2022, 12:53 PM

I just ran your first block of code on my system (with multiple video tracks and video events) on my system and this worked fine:

foreach (Track track in myVegas.Project.Tracks)
{
    if (track.IsVideo())
    {
        foreach (TrackEvent trackEvent in track.Events)
        {
            VideoEvent videoEvent = (VideoEvent)trackEvent;
            VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
            VideoMotionKeyframe keyframe = videoKeyframes[0];
            VideoMotionBounds bounds = keyframe.Bounds;

            keyframe.Bounds = bounds;
        }
    }
}

I ran my test on VEGAS Pro 20. What version of VEGAS are you using? Do you happen to have an "empty event" on the timeline?

 

Hey, I'm using VEGAS 18. This is what my timeline looks like:

And this is what the pan/crop on that event looks like:

RedyM wrote on 12/4/2022, 1:12 PM

I just ran your first block of code on my system (with multiple video tracks and video events) on my system and this worked fine:

foreach (Track track in myVegas.Project.Tracks)
{
    if (track.IsVideo())
    {
        foreach (TrackEvent trackEvent in track.Events)
        {
            VideoEvent videoEvent = (VideoEvent)trackEvent;
            VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
            VideoMotionKeyframe keyframe = videoKeyframes[0];
            VideoMotionBounds bounds = keyframe.Bounds;

            keyframe.Bounds = bounds;
        }
    }
}

I ran my test on VEGAS Pro 20. What version of VEGAS are you using? Do you happen to have an "empty event" on the timeline?

 

Update: I tried with VEGAS 20 but still no luck... Do you think you could share your project so I could try to run the script on my side using your VEGAS project?

jetdv wrote on 12/5/2022, 7:49 AM

It's just what you posted above. Here's exactly what I ran:
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

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

            foreach (Track track in myVegas.Project.Tracks)
            {
                if (track.IsVideo())
                {
                    foreach (TrackEvent trackEvent in track.Events)
                    {
                        VideoEvent videoEvent = (VideoEvent)trackEvent;
                        VideoMotionKeyframes videoKeyframes = videoEvent.VideoMotion.Keyframes;
                        VideoMotionKeyframe keyframe = videoKeyframes[0];
                        VideoMotionBounds bounds = keyframe.Bounds;

                        keyframe.Bounds = bounds;
                    }
                }
            }
            
        }

    }
}

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

I just dropped your code as the main part of my standard base script. Of course, it "does nothing" to the timeline but it does run correctly. You wouldn't need all of the "usings" that are listed here but those are just part of the base script I use.