Copy event attributes (script)

Jorge-Vegas wrote on 7/20/2023, 10:24 PM

Hello, I need to copy attributes from a video event and put them to another event. For example, I have two events selected and I want to copy some attributes from the first event and put them on the other event.

I need to do the same thing that can be done with the "selective paste of event attributes" option, I need to copy some attributes, such as: all video effects, transition in and out, pan/crop settings.

I need it to be the same as the "selective paste of event attributes" option which is accessed by right click, because otherwise I'll have to copy each thing independently and it will be crazy, plus I already tried and got nothing.

If I were to copy each attribute separately, firstly I don't understand how Vegas Pro doesn't have a script method that does the same thing as a basic context menu tool, and secondly: I've been having a hard time getting some particular attributes out of the event, but so far I haven't been able to get anything done with the pan/crop mask keyframes, if this isn't possible then my job will be half done.

What is the closest thing to the "selective pasting of event attributes" option that can be done? I need to copy many attributes, but the most important ones, for now, are the pan/crop keyframes, both position and mask.

Thank you very much in advance!

Comments

julioimolesi wrote on 7/23/2023, 10:30 AM

I need it too.. :/

Jorge-Vegas wrote on 7/23/2023, 10:41 AM

For my part, so far I have figured out how to get the names of the effects, the transitions, remove transitions, get information on the position keyframes of an event.  Surely each of these things can be copied exhaustively, but there are effects, transitions and keyframes that usually have too many features to copy them all.  Then, I still need to figure out how to access the mask keyframe information from the pan/crop menu, in the Vegas API I found absolutely nothing.

jetdv wrote on 7/23/2023, 12:34 PM

You can't access the Pan/Crop Mask from a script...

You can get all of the effect/transition Parameters from that effect/transition and just copy them all individually with a loop.

Jorge-Vegas wrote on 7/25/2023, 12:00 AM

You can't access the Pan/Crop Mask from a script...

You can get all of the effect/transition Parameters from that effect/transition and just copy them all individually with a loop.

It's incredible that you can't do anything with the mask but that you can copy all the parameters of an effect/transition, although I imagine that the latter will be another headache.

Jorge-Vegas wrote on 7/25/2023, 12:00 AM

Well, I'm stuck again, I see that copying all the attributes of an event will be impossible.

I'm just trying to copy the keyframes from one event and put them in another but I found some bugs/problems.

I have had no problem creating new keyframes in the target event using the position timecodes of the original keyframes, but after that I tried to set all the properties to the keyframe and problems arise.

First of all, here below are all the "properties" that I discovered that a keyframe can have, to later copy them all:
"Position","TopLeft, "TopRight", "BottomRight", "BottomLeft", "Rotation", "Center", "Type", "Bounds","Smoothness"

To start I use "Position" to create the keyframes and everything goes well, but then I have to put the other things on it. The first problem is that the "TopLeft", "TopRight", "BottomRight" and "BottomLeft" properties are "read only" so you can only know that information from a keyframe but you cannot edit it, not even when defining a new keyframe.

I have placed the other properties to the new keyframes but with another problem: there seems to be a compatibility problem between "Center" and "Rotation" with "Bounds", since almost everything looks good, even the "width" and "height" of the "box" (even without having used "TopLeft", etc), and also the symmetry of the view in case of having activated "invert horizontally", but the keyframes that should have rotation do not have it and even have it wrong also the "width" and "height", they only have the center of rotation well but that alone is useless. On the other hand, if I delete the "Bounds" line, the angle and center of rotation are created well but I lose everything else ("width", "height", inverted).

I have managed to get around the problem that "TopLeft", etc, are read only using "TopLeft.X", "TopLeft.Y", etc, I don't see that it has helped much, the problem with the rotation still persists.
Clearly if one parameter is wrong that will modify the others because they are "connected" but so far I can't successfully copy them all

How difficult is it to get a script that copies all the attributes of at least one keyframe?

jetdv wrote on 7/25/2023, 7:22 AM
To start I use "Position" to create the keyframes and everything goes well, but then I have to put the other things on it. The first problem is that the "TopLeft", "TopRight", "BottomRight" and "BottomLeft" properties are "read only" so you can only know that information from a keyframe but you cannot edit it, not even when defining a new keyframe.

Use "Bounds" instead. Bounds is all four of those properties so you only need to copy the Bounds to get all four. Then also copy the smoothness.

Also, look at "TopLeft.X" and "TopLeft.Y" - those should be read/write.

Jorge-Vegas wrote on 7/25/2023, 10:08 AM
To start I use "Position" to create the keyframes and everything goes well, but then I have to put the other things on it. The first problem is that the "TopLeft", "TopRight", "BottomRight" and "BottomLeft" properties are "read only" so you can only know that information from a keyframe but you cannot edit it, not even when defining a new keyframe.

Use "Bounds" instead. Bounds is all four of those properties so you only need to copy the Bounds to get all four. Then also copy the smoothness.

Also, look at "TopLeft.X" and "TopLeft.Y" - those should be read/write.

Yeah that's what I did and therein lies the problem with the rotation.  Just by using "Bounds" I already have the correct size of the "box", I can even add other properties and it works, but as soon as I add "Rotation", everything starts to fail.

As I said, I tried "TopLeft.X" and "TopLeft.Y" but it didn't help, it doesn't give me a "read only" error but they don't make any changes.

The problem seems to only be with "Rotation", when I use it in conjunction with other properties, because it itself does work.

jetdv wrote on 7/25/2023, 3:42 PM

What if you do rotation first and then the bounds?

Jorge-Vegas wrote on 7/25/2023, 5:30 PM

What if you do rotation first and then the bounds?

I've already tried all the possible combinations, but there are only changes when I alternate the order between "Rotation" and "Bounds", although it doesn't look good in any case.

 If "Bounds" is first, it happens that the keyframes created and that have rotation are left with an incorrect scale.  

If "Rotation" is first then the keyframes are left with the wrong scale and no rotation at all.  

I tried to solve the problem using "RotateBy" and "ScaleBy" but it also gives problem with keyframes that have a rotation of 0 or 360 degrees.

Jorge-Vegas wrote on 7/25/2023, 10:17 PM

Pan/crop attributes aside, I'm now working on copying the effects and transitions.

  Copying all the effects and transitions (in and out) was easy, but I couldn't copy their parameters.

I'll focus on the video effects which is the most important thing for me (I totally rule out accessing the animated effects keyframes, because it will be crazy to copy so many parameters). To begin with, I have watched the jetdv videos and I managed to get the name and label of the parameters, but I can't get their values.- In the "OFXParameter" class there is no "Value", so I tried with "GetValueAtTime" which is the only thing i found in the api and that is similar to what i need but it doesn't work.

So far I've accomplished that, copying all the effects and knowing their parameters, but I can't read their values, so I haven't tried to edit them either.

jetdv wrote on 7/26/2023, 7:35 AM
            //Reading effect parameters and keyframes for each parameter
            string s = "";
            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    foreach (TrackEvent evnt in myTrack.Events)
                    {
                        VideoEvent vEvnt = (VideoEvent)evnt;

                        foreach (Effect effect in vEvnt.Effects)
                        {
                            s = "Track " + (myTrack.Index + 1) + "  Event at " + evnt.Start;
                            if (effect.PlugIn.IsOFX)
                            {
                                OFXEffect ofx = effect.OFXEffect;
                                foreach (OFXParameter ofxparm in ofx.Parameters)
                                {
                                    if ((ofxparm.Name != "Presets") && (ofxparm.Label != "Preset") && (ofxparm.ParameterType.ToString() != "Page") && (ofxparm.ParameterType.ToString() != "Group") && (ofxparm.ParameterType.ToString() != "PushButton"))
                                    {
                                        s = s + "\r\nEffect: " + effect.Description + "      Parameter Name: " + ofxparm.Name + "     Parameter Label: " + ofxparm.Label + "     of type: " + ofxparm.ParameterType.ToString();
                                        switch (ofxparm.ParameterType.ToString())
                                        {
                                            case "RGB":
                                                {
                                                    OFXRGBParameter p1 = (OFXRGBParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p1.Keyframes.Count;
                                                    if (p1.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p1.Value.R + "," + p1.Value.G + "," + p1.Value.B;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXRGBKeyframe k1 in p1.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.R + "," + k1.Value.G + "," + k1.Value.B + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "RGBA":
                                                {
                                                    OFXRGBAParameter p1 = (OFXRGBAParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p1.Keyframes.Count;
                                                    if (p1.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p1.Value.R + "," + p1.Value.G + "," + p1.Value.B + "," + p1.Value.A;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXRGBAKeyframe k1 in p1.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.R + "," + k1.Value.G + "," + k1.Value.B + "," + k1.Value.A + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Double":
                                                {
                                                    OFXDoubleParameter p2 = (OFXDoubleParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value.ToString();
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXDoubleKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.ToString() + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Double2D":
                                                {
                                                    OFXDouble2DParameter p2 = (OFXDouble2DParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value.X + "," + p2.Value.Y;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXDouble2DKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.X + "," + k1.Value.Y + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Double3D":
                                                {
                                                    OFXDouble3DParameter p2 = (OFXDouble3DParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value.X + "," + p2.Value.Y + "," + p2.Value.Z;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXDouble3DKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.X + "," + k1.Value.Y + "," + k1.Value.Z + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Integer":
                                                {
                                                    OFXIntegerParameter p2 = (OFXIntegerParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXIntegerKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Integer2D":
                                                {
                                                    OFXInteger2DParameter p2 = (OFXInteger2DParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value.X + "," + p2.Value.Y;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXInteger2DKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.ToString() + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Integer3D":
                                                {
                                                    OFXInteger3DParameter p2 = (OFXInteger3DParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p2.Keyframes.Count;
                                                    if (p2.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p2.Value.X + "," + p2.Value.Y + "," + p2.Value.Z;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXInteger3DKeyframe k1 in p2.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.ToString() + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Choice":
                                                {
                                                    OFXChoiceParameter p3 = (OFXChoiceParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p3.Keyframes.Count;
                                                    if (p3.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p3.Value.ToString();
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXChoiceKeyframe k1 in p3.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.ToString() + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Boolean":
                                                {
                                                    OFXBooleanParameter p4 = (OFXBooleanParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p4.Keyframes.Count;
                                                    if (p4.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p4.Value;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXBooleanKeyframe k1 in p4.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "String":
                                                {
                                                    OFXStringParameter p5 = (OFXStringParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p5.Keyframes.Count;
                                                    if (p5.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p5.Value;
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXStringKeyframe k1 in p5.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            case "Custom":
                                                {
                                                    OFXCustomParameter p5 = (OFXCustomParameter)ofx[ofxparm.Name];
                                                    s = s + "\r\n\tKeyFrame Count = " + p5.Keyframes.Count;
                                                    if (p5.Keyframes.Count == 0)
                                                    {
                                                        s = s + "\r\n\t\tSingle Keyframe value = " + p5.Value.ToString();
                                                    }
                                                    else
                                                    {
                                                        foreach (OFXCustomKeyframe k1 in p5.Keyframes)
                                                        {
                                                            s = s + "\r\n\t\tKeyframe at " + k1.Time + "  Value = " + k1.Value.ToString() + "  Interpolation = " + k1.Interpolation;
                                                        }
                                                    }
                                                    break;
                                                }
                                            default:
                                                {
                                                    s = s + "\r\n\t\tUnknown Parameter Type";
                                                    break;
                                                }
                                        }
                                    }
                                }
                            }
                            MessageBox.Show(s);
                        }
                    }
                }
            }

Each parameter is keyframed separately so you have to do each one separately. Here's how you read them (and, yes, it is the "Value" you read.