Unable to access track motion class.

lRaulMN7 wrote on 4/21/2019, 4:26 AM

Hello!

I'm trying to access the motion kayframes of a video track. Or at least, that's what I think I want to do, because I'm spanish and I'm translating the names by my own, that's why I'll attach a photo just in case.

So in the Vegas API there is a class called TrackMotion Class, which provides access to video track motion data. It seems to have an attribute with the motionKeyframes so I might be able to work with that.

However I'm not able to reach such class!. Like, how do I get an instance of such class from my project? There are no Trackmotion instances in the Track class, so I'm a bit lost there.

If anyone wants to give a try, this simple .cs code should be a good point to start.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using ScriptPortal.Vegas; 

public class EntryPoint {
    
    public void FromVegas(Vegas vegas) {

        Project proj = vegas.Project;
        foreach (Track track in proj.Tracks)
        {
           if(track.Selected && track.IsVideo()){
                 MessageBox.Show("I select track 3 for instance, and now I want to access the track motion keyframes here");
           }
        }
     }
}

 

Thanks in advance :)

Comments

jetdv wrote on 4/22/2019, 1:12 PM

This is not exactly what you are looking for but should hopefully give you a guideline how to access the pieces you want to access. Here is how you can export track motion (elt is basically the file being exported to):

 

                    ExportVideoTrackMotion(elt, "TrackMotion", videoTrack.TrackMotion);
                    if (videoTrack.IsCompositingParent)
                        ExportVideoTrackMotion(elt, "ParentTrackMotion", videoTrack.ParentTrackMotion);


 

        private static void ExportVideoTrackMotion(XmlElement parent, string motionType, TrackMotion tm)
        {
            Common.WriteToLog("    Export TrackMotion");

            XmlElement elt = AddChild(parent, motionType);
            ChildBoolean(elt, "GlowEnabled", tm.GlowEnabled);
            ChildBoolean(elt, "ShadowEnabled", tm.ShadowEnabled);
            ChildBoolean(elt, "HasGlowData", tm.HasGlowData);
            ChildBoolean(elt, "HasShadowData", tm.HasShadowData);
            ChildBoolean(elt, "HasMotionData", tm.HasMotionData);
            ChildObject(elt, "ScaleFactors", tm.ScaleFactors);
            ExportTrackMotionGlow(elt, tm.GlowKeyframes);
            ExportTrackMotionShadow(elt, tm.ShadowKeyframes);
            ExportTrackMotion(elt, tm.MotionKeyframes);
        }

        private static void ExportTrackMotionGlow(XmlElement parent, TrackGlowKeyframeList glowList)
        {
            XmlElement elt = AddChild(parent, "TrackGlowKeyframes");
            elt.SetAttribute("Count", glowList.Count.ToString(myNumberFormat));
            foreach (TrackGlowKeyframe tgk in glowList)
            {
                if (tgk.Position >= ThemeStart && tgk.Position <= ThemeEnd)
                {
                    ExportTrackMotionGlowKeyframe(elt, tgk);
                }
            }
        }

        private static void ExportTrackMotionGlowKeyframe(XmlElement parent, TrackGlowKeyframe glowKF)
        {
            XmlElement elt = AddChild(parent, "TrackGlowKeyframe");
            ChildDouble(elt, "Blur", glowKF.Blur);
            AddVideoColor(elt, "Color", glowKF.Color);
            ChildDouble(elt, "Height", glowKF.Height);
            ChildDouble(elt, "Intensity", glowKF.Intensity);
            ChildDouble(elt, "OrientationZ", glowKF.OrientationZ);
            ChildTimecode(elt, "Position", glowKF.Position - leftOffset);
            ChildDouble(elt, "PositionX", glowKF.PositionX);
            ChildDouble(elt, "PositionY", glowKF.PositionY);
            ChildDouble(elt, "RotationOffsetX", glowKF.RotationOffsetX);
            ChildDouble(elt, "RotationOffsetY", glowKF.RotationOffsetY);
            ChildDouble(elt, "RotationZ", glowKF.RotationZ);
            ChildDouble(elt, "Smoothness", glowKF.Smoothness);
            ChildDouble(elt, "Width", glowKF.Width);
            ChildObject(elt, "Type", glowKF.Type);
        }

        private static void ExportTrackMotionShadow(XmlElement parent, TrackShadowKeyframeList shadowList)
        {
            XmlElement elt = AddChild(parent, "TrackShadowKeyframes");
            elt.SetAttribute("Count", shadowList.Count.ToString(myNumberFormat));
            foreach (TrackShadowKeyframe tgk in shadowList)
            {
                if (tgk.Position >= ThemeStart && tgk.Position <= ThemeEnd)
                {
                    ExportTrackMotionShadowKeyframe(elt, tgk);
                }
            }
        }

        private static void ExportTrackMotionShadowKeyframe(XmlElement parent, TrackShadowKeyframe shadowKF)
        {
            XmlElement elt = AddChild(parent, "TrackShadowKeyframe");
            ChildDouble(elt, "Blur", shadowKF.Blur);
            AddVideoColor(elt, "Color", shadowKF.Color);
            ChildDouble(elt, "Height", shadowKF.Height);
            ChildDouble(elt, "Intensity", shadowKF.Intensity);
            ChildDouble(elt, "OrientationZ", shadowKF.OrientationZ);
            ChildTimecode(elt, "Position", shadowKF.Position - leftOffset);
            ChildDouble(elt, "PositionX", shadowKF.PositionX);
            ChildDouble(elt, "PositionY", shadowKF.PositionY);
            ChildDouble(elt, "RotationOffsetX", shadowKF.RotationOffsetX);
            ChildDouble(elt, "RotationOffsetY", shadowKF.RotationOffsetY);
            ChildDouble(elt, "RotationZ", shadowKF.RotationZ);
            ChildDouble(elt, "Smoothness", shadowKF.Smoothness);
            ChildDouble(elt, "Width", shadowKF.Width);
            ChildObject(elt, "Type", shadowKF.Type);
        }

        private static void ExportTrackMotion(XmlElement parent, TrackMotionKeyframeList motionList)
        {
            XmlElement elt = AddChild(parent, "TrackMotionKeyframes");
            elt.SetAttribute("Count", motionList.Count.ToString(myNumberFormat));
            foreach (TrackMotionKeyframe tgk in motionList)
            {
                if (tgk.Position >= ThemeStart && tgk.Position <= ThemeEnd)
                {
                    ExportTrackMotionKeyframe(elt, tgk);
                }
            }
        }

        private static void ExportTrackMotionKeyframe(XmlElement parent, TrackMotionKeyframe motionKF)
        {
            XmlElement elt = AddChild(parent, "TrackMotionKeyframe");
            ChildDouble(elt, "Depth", motionKF.Depth);
            ChildDouble(elt, "Height", motionKF.Height);
            ChildDouble(elt, "OrientationX", motionKF.OrientationX);
            ChildDouble(elt, "OrientationY", motionKF.OrientationY);
            ChildDouble(elt, "OrientationZ", motionKF.OrientationZ);
            ChildTimecode(elt, "Position", motionKF.Position - leftOffset);
            ChildDouble(elt, "PositionX", motionKF.PositionX);
            ChildDouble(elt, "PositionY", motionKF.PositionY);
            ChildDouble(elt, "PositionZ", motionKF.PositionZ);
            ChildDouble(elt, "RotationOffsetX", motionKF.RotationOffsetX);
            ChildDouble(elt, "RotationOffsetY", motionKF.RotationOffsetY);
            ChildDouble(elt, "RotationOffsetZ", motionKF.RotationOffsetZ);
            ChildDouble(elt, "RotationX", motionKF.RotationX);
            ChildDouble(elt, "RotationY", motionKF.RotationY);
            ChildDouble(elt, "RotationZ", motionKF.RotationZ);
            ChildDouble(elt, "Smoothness", motionKF.Smoothness);
            ChildDouble(elt, "Width", motionKF.Width);
            ChildObject(elt, "Type", motionKF.Type);
        }

 

lRaulMN7 wrote on 4/29/2019, 6:56 AM

Hi! Thanks for your reply.

                   ExportVideoTrackMotion(elt, "TrackMotion", videoTrack.TrackMotion);
                    if (videoTrack.IsCompositingParent)
                        ExportVideoTrackMotion(elt, "ParentTrackMotion", videoTrack.ParentTrackMotion);

I don't see the attribute "TrackMotion" in the videoTrack class. At least there are no references in the VEGAS API. :(

VEGASDerek wrote on 4/29/2019, 10:14 AM

It is indeed available in the VideoTrack class. I believe its omission in the API document was unintended.

Each VideoClass has access to a TrackMotion property and the TrackMotion class should be available in the API document to explain how to use the TrackMotion property.

lRaulMN7 wrote on 4/29/2019, 10:56 AM

It is indeed available in the VideoTrack class. I believe its omission in the API document was unintended.

Each VideoClass has access to a TrackMotion property and the TrackMotion class should be available in the API document to explain how to use the TrackMotion property.

True, it works. I was just skeptical about it because I wasn't finding any references in the API. Thanks @VEGASDerek and @jetdv .