How to move Position X Center by 100 pixels in the Pan\Crop of Event

Julian-M wrote on 4/23/2025, 11:40 AM

Hello! 👋
Please help me change the script 🙏.
Currently the script increases the "Rotation - X Center" parameter by 100 pixels in the Pan\Crop tool for each animation key of each selected video event ➡.
But I need to increase "Position - X Center".
This should move the entire panorama frame to the right.
Unfortunately, I could not find how to access this parameter in VegasAPI.
Thanks in advance!
Here is the script code:

using System;
using ScriptPortal.Vegas;

namespace PanCropShiftX
{
    public class Class1
    {
        public Vegas myVegas;

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

            foreach (Track track in vegas.Project.Tracks)
            {
                if (track.IsVideo())
                {
                    foreach (VideoEvent evnt in track.Events)
                    {
                        if (evnt.Selected)
                        {
                            ShiftPanCropX(evnt);
                        }
                    }
                }
            }
        }

        public void ShiftPanCropX(VideoEvent videoEvent)
        {
            VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes;

            foreach (VideoMotionKeyframe keyframe in keyframes)
            {
                VideoMotionVertex center = keyframe.Center;

                // Shift the center along X by 100
                VideoMotionVertex newCenter = new VideoMotionVertex(center.X + 100.0f, center.Y);

                keyframe.Center = newCenter;
            }

            myVegas.UpdateUI();
        }
    }

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


 

Comments

jetdv wrote on 4/23/2025, 12:15 PM

There is no "center" position. There's "left" position and "right" position. If you don't want to resize I suppose you could change both "left" and "right" plus the same value. Maybe something like:

                VideoMotionBounds myBounds = keyframe.Bounds;
                myBounds.TopLeft.X = myBounds.TopLeft.X + 100.0f;
                myBounds.TopRight.X = myBounds.TopRight.X + 100.0f;
                keyframe.Bounds = myBounds;

 

Julian-M wrote on 4/23/2025, 1:57 PM

There is no "center" position. There's "left" position and "right" position. If you don't want to resize I suppose you could change both "left" and "right" plus the same value. Maybe something like:

                VideoMotionBounds myBounds = keyframe.Bounds;
                myBounds.TopLeft.X = myBounds.TopLeft.X + 100.0f;
                myBounds.TopRight.X = myBounds.TopRight.X + 100.0f;
                keyframe.Bounds = myBounds;

Oh, thank you, Sir! 😃
Now I have 4 scripts for quickly moving selected events in the frame (with or without animation keys). This will come in handy when changing the orientation of projects from 16x9 to 9x16 and vice versa ♻.
If someone else finds this useful, the scripts are here.

Could you please also tell me how to make a proportional increase/decrease of the entire panorama in percentage? 💯
For example, increase or decrease a video event by 10% in the frame.
But in order to preserve the aspect ratio of the panorama.

jetdv wrote on 4/23/2025, 2:08 PM

Once again, you change the bounds. But only change one side to change the size.

Or change the size directly using "ScaleBy". See here for ScaleBy and RotateBy:

        public void ScaleKeyframe(VideoMotionKeyframe keyframe, float szChange, float rotAngle)
        {
            float cWidth = (1 / (szChange / 100));
            float cHeight = (1 / (szChange / 100));

            if (szChange > 100)
            {
                cWidth = (szChange / 100);
                cHeight = (szChange / 100);
            }

            VideoMotionVertex bounds = new VideoMotionVertex(cWidth, cHeight);

            keyframe.ScaleBy(bounds);
            keyframe.RotateBy((rotAngle * (Math.PI / 180)));
        }

 

Julian-M wrote on 4/23/2025, 3:39 PM

Once again, you change the bounds. But only change one side to change the size.

Or change the size directly using "ScaleBy". See here for ScaleBy and RotateBy:

Thank you, Sir, you helped me a lot! 🙌✨
Now I have two more useful scripts: one to increase a video event by 10%, the other to decrease it by 10%.
If someone else needs this, the scripts are here.

Julian-M wrote on 4/23/2025, 5:47 PM

Also, together with the GPT chat, a script was created that displays a window with settings for all six scripts ⚙:

move all UP on pan by 100 pixels PanoramaOffsetX.cs
move all DOWN on pan by 100 pixels PanoramaOffsetX.cs
move all LEFT on pan by 100 pixels PanoramaOffsetX.cs
move all RIGHT on pan by 100 pixels PanoramaOffsetX.cs
Increase Event Scale by 10 percent.cs
Decrease Event Scale by 10 percent.cs

The settings allow you to set the size in pixels for the four movement scripts and the number of percent for the increase scripts 📜.
The settings script "SetMovingScalling.cs" creates a text document "Moving_Scalling_Settings.txt" in the "Script Menu" directory, and the settings are read from this text file when executing the other six scripts ♻.
I really like how this works, especially if you add all these scripts to the toolbar 😁.
Hopefully this will be useful for someone else as well.
Special thanks to Ser @jetdv for your quick and accurate help! 🙌
🔗Here is a link with the listed scripts and icons for them.

Julian-M wrote on 4/24/2025, 7:18 AM

There is no "center" position. There's "left" position and "right" position. If you don't want to resize I suppose you could change both "left" and "right" plus the same value. Maybe something like:

I have a small problem with the movement scripts for events with a non-zero Rotation parameter 😬. For such events, the movement is not strictly vertical or horizontal, but in the direction of the tilt. In general, this is logical, but since these scripts are designed to move events in the frame without using Pan\Crop window, I would like the movement to always occur only vertically or horizontally, regardless of the rotation of the events 🔄.
How can this be achieved?

Another problem is that with a non-zero Event Pan Rotation value, using the script causes a change in the size of the panorama boundaries, when with a zero rotation this does not happen ↔.

For movement without rotation, the following lines work fine for me (the directions are specified in terms of the actual movement of objects on the screen in the preview window, since the Pan\Crop window is closed):

myBounds.BottomRight.X = myBounds.BottomRight.X - 100.0f * 2; //move 100 pixels to the right;
myBounds.BottomRight.X = myBounds.BottomRight.X + 100.0f * 2; //move 100px left;
myBounds.BottomRight.Y = myBounds.BottomRight.Y - 100.0f * 2; //move 100px down;
myBounds.BottomRight.X = myBounds.BottomRight.X + 100.0f * 2; //move 100px up;

🤖I described my rotation problem to GPT chat and he tried many times to account for it, but to no avail...
The last thing he wrote should have worked like this:

  1. current rotation value of the event and animation key is saved to the clipboard;
  2. rotation value is reset;
  3. action of moving the borders is performed;
  4. action of moving the center of rotation is performed inversely proportional;
  5. original rotation value is returned;

The script from the chat helped to solve the problem of changing the size of the borders 👍, but there remains a problem with deviation from the horizon or vertical when moving events with rotation.

It looks like this, but unfortunately it doesn't work the same way 😕:

public void ShiftPanCropX(VideoEvent videoEvent)
{
    float moveAmount = ReadMoveAmountFromFile();
    VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes;
    foreach (VideoMotionKeyframe keyframe in keyframes)
    {
        float originalRotation = (float)keyframe.Rotation;
        
        // Zero out the rotation to correctly shift the panorama in X
        keyframe.Rotation = 0.0;
        VideoMotionBounds myBounds = keyframe.Bounds;

        // Shift the entire frame, maintaining the size
        myBounds.BottomRight.X = myBounds.BottomRight.X - moveAmount * 2; //moveAmount is substituted from the text document with settings, which I wrote about in the previous post.

        keyframe.Bounds = myBounds;

        // Also shift the rotation center so that it stays in the same place visually
        VideoMotionVertex center = keyframe.Center;
        center.X += moveAmount;
        keyframe.Center = center;

        // Restore the original rotation
        keyframe.Rotation = originalRotation;
    }
    myVegas.UpdateUI();
}

 

jetdv wrote on 4/24/2025, 12:33 PM

The last option is what I would have suggested... remove the rotation, move, and then reset the rotation. Why are you changing the "center"?

Julian-M wrote on 4/24/2025, 3:52 PM

Why are you changing the "center"?

It seemed to me that this is a necessary step to achieve strictly horizontal (or vertical) movement ⏩.
I tried to simulate this sequence using animation keys set manually 🔹.
It seems that this helped me to confirm that returning the rotation point to the position before the border moving step is the key to success.
I recorded this on .
I also attach the project file to this post.

But in reality, for some reason, the script does not work properly... 💁‍♂️

By returning the value of the original rotation, the script seems to ignore the change in the position of the rotation center, and the final position of the event in the frame deviates from the axis 📉.

jetdv wrote on 4/24/2025, 9:08 PM

So you are pre-adding all of the keyframes and then adjusting the keyframes already added?

What if the script adds the keyframes at the proper location and then just sets the values?