Script Copy Paste Pan-Crop

maumau wrote on 6/7/2014, 5:43 AM
Hi!
I recently started writing scripts and I'm currently writing one to copy and past the pan crop settings.
But there's a problem:
The coordinates and rotation are copied correctly, but I can't apply them correctly.
Do you have any tips on how to apply those correctly?

This is what I tried:
(C# Code, "events" are the selected VideoEvents)

for (int i = 0; i < events.Count; i++)
{

events[i].VideoMotion.Keyframes[0].Bounds = new VideoMotionBounds(
topLeftX, topLeftY, topRightX, topRightY, bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
events[i].VideoMotion.Keyframes[0].Center.X = rotationCenterX;
events[i].VideoMotion.Keyframes[0].Center.Y = rotationCenterY;
events[i].VideoMotion.Keyframes[0].Rotation = rotation;
}

Comments

Gary James wrote on 6/7/2014, 9:57 AM
You have created a loop that generates an incrementing index number, but you never use it.

This code should be referencing the events collection with the index value: events[ i ] .
for (int i = 0; i < events.Count; i++)
{
events.VideoMotion.Keyframes[0].Bounds = new VideoMotionBounds(
topLeftX, topLeftY, topRightX, topRightY, bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
events.VideoMotion.Keyframes[0].Center.X = rotationCenterX;
events.VideoMotion.Keyframes[0].Center.Y = rotationCenterY;
events.VideoMotion.Keyframes[0].Rotation = rotation;
}

maumau wrote on 6/7/2014, 2:21 PM
Sorry, the copy&paste of the code went wrong.
The forum deletes [ i ], if there are no spaces between the brackets and the i.
I did use events [ i ]:

for (int i = 0; i < events.Count; i++)
{

events[ i ].VideoMotion.Keyframes[0].Bounds = new VideoMotionBounds(
topLeftX, topLeftY, topRightX, topRightY, bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
events[ i ].VideoMotion.Keyframes[0].Center.X = rotationCenterX;
events[ i ].VideoMotion.Keyframes[0].Center.Y = rotationCenterY;
events[ i ].VideoMotion.Keyframes[0].Rotation = rotation;
}

For testing, I created two scripts, one for pasting the bounds and one for pasting the rotation and the center of the rotation.
Here are the test results:
move c&p move -> works
rotate c&p rotate -> works
move&rotate c&p rotate -> works (correct rotation)
move&rotate c&p move -> image gets too big

So, seems like the problem is setting the bounds, when the image has also been rotated.
I get the same problem (image too big), when c&p move and rotation:
The rotation is correct, but the bounds are wrong.
Warper wrote on 6/9/2014, 1:35 AM
You do not show essential parts of the script. We never know how you get topLeftX, for example.
Print them all - local values on every cycle repeat, values that got inside vegas objects after assignments in cycle. Dump them to some file and then compare to each other and to numbers in UI.

maumau wrote on 6/9/2014, 5:44 AM
Edit:

AH! I think I got it!

For others, who have the same problem:
Earlier I tried to simply copy the bounds, rotation and rotation center.
What I did now is:
1.) Get the rotation
2.) Set the rotation to 0, to get the correct bounds
3.) Get bounds and rotation center
3.) Restore rotation
4.) Simply paste all that info to the selected event.