I am attempting to create a script for Vegas Pro that reverses the sequence of keyframes in the Event Pan/Crop. However, I am encountering errors in my script. Specifically, I am receiving the error "Object reference is required for the non-static field, method, or property 'ScriptPortal.Vegas.Vegas.Project.get'."
The goal of the script is to mirror the sequence of keyframes, similar to flipping an image direction. For example, if you have multiple keyframes on the Pan/Crop timeline, the script should rearrange them so that their order is reversed. The idea is akin to dragging keyframes along the timeline to reverse their positions manually, but automated via the script.
Could someone assist me in resolving this issue and achieving the desired outcome? Any help with correcting the script or understanding the error would be greatly appreciated.
using System;
using System.Collections.Generic;
using ScriptPortal.Vegas;
using System.Windows.Forms; // Adicione referência ao System.Windows.Forms
public class Script
{
public void Main()
{
// Obtenha o projeto atual
Project project = GetProjectFromVegas();
if (project == null)
{
ShowMessage("Nenhum projeto encontrado.");
return;
}
// Obtenha o evento de vídeo selecionado
VideoEvent videoEvent = GetSelectedVideoEvent(project);
if (videoEvent == null)
{
ShowMessage("Nenhum evento de vídeo selecionado.");
return;
}
// Acesse os keyframes de VideoMotion
VideoMotion videoMotion = videoEvent.VideoMotion;
if (videoMotion == null)
{
ShowMessage("Nenhum movimento de vídeo disponível.");
return;
}
List<VideoMotionKeyframe> keyframes = new List<VideoMotionKeyframe>();
foreach (var keyframe in videoMotion.Keyframes)
{
keyframes.Add(keyframe);
}
// Inverta os keyframes
keyframes.Reverse();
// Limpe os keyframes existentes
videoMotion.Keyframes.Clear();
// Aplique os keyframes invertidos
foreach (var keyframe in keyframes)
{
videoMotion.Keyframes.Add(keyframe);
}
ShowMessage("Keyframes invertidos.");
}
private Project GetProjectFromVegas()
{
// Use o método global 'Vegas' para acessar o projeto
return ScriptPortal.Vegas.Vegas.Project;
}
private VideoEvent GetSelectedVideoEvent(Project project)
{
// Itera sobre as trilhas e eventos no projeto
foreach (Track track in project.Tracks)
{
foreach (TrackEvent trackEvent in track.Events)
{
if (trackEvent.Selected)
{
return trackEvent as VideoEvent;
}
}
}
return null;
}
private void ShowMessage(string message)
{
// Exibe uma caixa de mensagem
MessageBox.Show(message, "Script Vegas Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}