I'm pasting in two scripts: The first one works and takes highlighted media and adjusts the X Center and Y Center by a specific amount relative to where they started out, here's the working script:
using System;
using System.Windows.Forms; // Required for MessageBox
using ScriptPortal.Vegas;
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
// Assigning variables for X and Y position adjustments
float xAdjustment = 38.0f; // Change this value for X position adjustment
float yAdjustment = -189.0f; // Change this value for Y position adjustment
bool isMediaSelected = false;
foreach (Track track in vegas.Project.Tracks)
{
if (track.IsVideo())
{
foreach (TrackEvent evnt in track.Events)
{
if (evnt.Selected)
{
isMediaSelected = true; // At least one media is selected
VideoEvent vEvent = (VideoEvent)evnt;
VideoMotionKeyframes vKeyframes = vEvent.VideoMotion.Keyframes;
// Remove all keyframes except the first one
for (int i = vKeyframes.Count - 1; i > 0; i--)
{
vKeyframes.Remove(vKeyframes[i]);
}
// Adjust the first keyframe's X and Y position
VideoMotionKeyframe firstKeyframe = vKeyframes[0];
// Create the amount to move using the assigned X and Y adjustments
VideoMotionVertex moveByAmount = new VideoMotionVertex(xAdjustment, yAdjustment);
// Apply the movement to the keyframe
firstKeyframe.MoveBy(moveByAmount);
}
}
}
}
// If no media was selected, show a message box
if (!isMediaSelected)
{
MessageBox.Show("Highlight the clip you want to move first", "No Clip Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
I'd think that creating a similar script that does the same thing but just assigns the X Center and Y Center to a fixed number (not a relative number based on where the media was previously) would be a simple change but it's giving errors, here's what I tried to do:
using System;
using System.Windows.Forms; // Required for MessageBox
using ScriptPortal.Vegas;
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
// Assigning fixed values for X and Y center positions
float fixedXCenter = 1911.8f;
float fixedYCenter = 1481.3f;
bool isMediaSelected = false;
foreach (Track track in vegas.Project.Tracks)
{
if (track.IsVideo())
{
foreach (TrackEvent evnt in track.Events)
{
if (evnt.Selected)
{
isMediaSelected = true; // At least one media is selected
VideoEvent vEvent = (VideoEvent)evnt;
VideoMotionKeyframes vKeyframes = vEvent.VideoMotion.Keyframes;
// Remove all keyframes except the first one
for (int i = vKeyframes.Count - 1; i > 0; i--)
{
vKeyframes.Remove(vKeyframes[i]);
}
// Adjust the first keyframe's X and Y position
VideoMotionKeyframe firstKeyframe = vKeyframes[0];
// Move the keyframe to the fixed X and Y positions
VideoMotionVertex moveByAmount = new VideoMotionVertex(fixedXCenter - firstKeyframe.Position.X, fixedYCenter - firstKeyframe.Position.Y);
firstKeyframe.MoveBy(moveByAmount);
}
}
}
}
// If no media was selected, show a message box
if (!isMediaSelected)
{
MessageBox.Show("Highlight the clip you want to adjust first", "No Clip Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
Is there a different method I can use to set a fixed position for highlighted media versus relative position? I'm actually trying to assign all four of these variables to a fixed position, but was trying to get the X Center and Y Center to work first before trying to add in the Width and Height. Here are the four fixed variables I want to assign in the script:
Width: 3,401.8
Height: 2362.3
X Center: 1911.8
Y Center: 1481.3
Thanks for any help you can provide, yay! :-)
(PS - I'm using Vegas Pro 20, I'm not aware that scripts behave any differently whether it's 19, 20, 21, 22, but if they do please let me know.)