www.jetdv.com Forum Index Edward Troxel
Vegas Scripting and Newsletters
Home of Excalibur and Montage Magic
 
 FAQ   Search   Memberlist   Usergroups   Register   Profile 
 Log in to check your private messagesLog in to check your private messages   Log inLog in 

Move Selected Video Track Overlapping Previous
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ
View previous topic :: View next topic  
Author Message
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Mon Oct 29, 2007 2:03 am    Post subject: Move Selected Video Track Overlapping Previous Reply with quote

I want to write a C# script to do the following. I need a little help getting started. I also want to assign it to a key sequence or button on the toolbar.

1) Select the video track under the cursor. (it may already be selected by the user).
2) Move the track to the left so the beginning of the selected track overlaps the end of the previous track by :10 (or, a variation of the script would be to add a Flash transition for :10 instead)

Edit 10/29/07- I think the algorithm would be somthing like this, I need some starter C# code though.
- Search through all the events in the track, load their index into an array. (This may take a lot of time, maybe an easier way?)
- StartTime(CurrentEvent) = EndTime(CurrentEvent-1) - 0:10
- Sett Transition to Fade or Whatever.
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Mon Oct 29, 2007 12:52 pm    Post subject: Reply with quote

Do you have multiple video tracks? If yes, you also need some way of knowing WHICH video track to move. You don't need to actually load them into an array but you WILL need to go through all events on the track. However, I'd probably change:

- StartTime(CurrentEvent) = EndTime(CurrentEvent-1) - 0:10

to:

- IF (StartTime(CurrentEvent) >= the cursor position) then StartTime(CurrentEvent) = EndTime(CurrentEvent-1) - 0:10

That way you wouldn't move any events to the left of the cursor.
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Mon Oct 29, 2007 10:04 pm    Post subject: Reply with quote

Thanks Ed,

After rereading my post again I was using the term TRACK incorrectly. Based on your response, I think you knew what I meant. To clarify, I want to move the selected EVENT start time to be :10 before the end of the previous EVENT end time, and then add a trasition.

I got the script below compiling in Visual Studio 2005 Express and running it in Vegas (big step for me!).

The script gets me to the first selected EVENT, regardless of number of tracks. Now, how do I get the end time of the prior event without using an Array or collection of all events?


Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;



namespace VegasMoveEvent
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
 
            foreach (Track track in vegas.Project.Tracks)
            {
                foreach (TrackEvent trackEvent in track.Events)
                {
                    if (trackEvent.Selected)
                    {

                        // Found First Selected Event.
                        // ADD IF (StartTime(CurrentEvent) >= the cursor position)
                        // then StartTime(CurrentEvent) = EndTime(CurrentEvent-1) - 0:10

                    }
                }
            }
        }
    }
}
Back to top
View user's profile Send private message
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Mon Oct 29, 2007 11:29 pm    Post subject: Reply with quote

Being better at C++ than C#, this is how I got it to work using and Array. There must be a better way to get the previous element in a foreach loop?

Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;



namespace VegasMoveEvent
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
 
            TrackEvent [] eventArray;
            eventArray = new TrackEvent[1000];

            int i;

            Timecode overlap = new Timecode("00:00:00.10");   

            foreach (Track track in vegas.Project.Tracks)
            {
                i = 0;
                foreach (TrackEvent trackEvent in track.Events)
                {
                    eventArray[i] = trackEvent;
                    i = i + 1;
                    if (trackEvent.Selected)
                    {
                        MessageBox.Show(eventArray[i - 2].End.ToString());
                        trackEvent.Start = eventArray[i - 2].End - overlap;
                    }
                }
            }
        }
    }
}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Tue Oct 30, 2007 1:34 am    Post subject: Reply with quote

Using an array works fine. The only issue I can see is if the FIRST event is selected. You might want to check for that.

Using your first method, I would have created a "PrevEvent" variable and set it to the "current event" just before moving it to the "next event".
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Tue Oct 30, 2007 2:30 am    Post subject: Reply with quote

I took into account some of the suggestions. This version is better, it does not allow the first track to be operated on. Now off to add different transitions.

Code:

// Sony Vegas C# Script
// Moves selected track event to start at the end of the previous track event - :10 seconds.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;


namespace VegasMoveEvent
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
            TrackEvent priorEvent;
            priorEvent = null;

            Timecode overlap = new Timecode("00:00:00.10");   

            foreach (Track track in vegas.Project.Tracks)
            {
                foreach (TrackEvent trackEvent in track.Events)
                {
                    if (trackEvent.Selected)
                    {
                        if (trackEvent.Index == 0)
                        {
                            MessageBox.Show("First Event Not Allowed!!");
                        }
                        else
                        {
                            trackEvent.Start = priorEvent.End - overlap;
                        }
                    }
                    else
                    {
                        priorEvent = trackEvent;
                    }

                }
            }
        }
    }
}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Tue Oct 30, 2007 12:55 pm    Post subject: Reply with quote

You're getting closer. To be safer, I would change:

trackEvent.Start = priorEvent.End - overlap;


to this:

Timecode offset = trackEvent.Offset;
trackEvent.Start = priorEvent.End - overlap;
trackEvent.Offset = offset;
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Tue Oct 30, 2007 1:30 pm    Post subject: Reply with quote

Thanks Ed, I'll try these changes tonight.

In the Sony Vegas 8 Pro SDK documentation(VegasScriptFAQ.html) there seems to be an inconsistency or I'm not understaing things correctly.

They give an example function that takes two arguments. However,when they use it, it they only pass one arguemnt. The function is not overloaded??

Quote:

2.3: How do I make a one second dissolve at the beginning and end of a video event?

Code:

Effect CreateTransitionEffect(Vegas vegas, String plugInName) {  //TWO ARGUMENTS
    PlugInNode plugIn = vegas.Transitions.GetChildByName(plugInName);
    if (null == plugIn)
        throw new ApplicationException(String.Format("Failed to find plug-in: '{0}'", plugInName));
    return new Effect(plugIn);
}


Effect fadeInTx = CreateTransitionEffect("Sony Dissolve");  //ONE ARGUMENT
videoEvent.FadeIn.Transition = fadeInTx;
fadeInTx.Preset = "Additive Dissolve";
Effect fadeOutTx = CreateTransitionEffect("Sony Slide");
videoEvent.FadeOut.Transition = fadeOutTx;
fadeOutTx.Preset = "Additive Dissolve";
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Tue Oct 30, 2007 1:51 pm    Post subject: Reply with quote

Get rid of:
Vegas vegas,

That shouldn't need to be passed to the routine.


NOTE: That doesn't actually CREATE a transition, it changes a transition to be that TYPE of transition.
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Tue Oct 30, 2007 11:11 pm    Post subject: Reply with quote

Edward Troxel wrote:

Timecode offset = trackEvent.Offset;
trackEvent.Start = priorEvent.End - overlap;
trackEvent.Offset = offset;



Offset is not defined for the trackEvent class. trackEvent.Offset gives a syntax error. What is this supposed to be doing?
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Wed Oct 31, 2007 12:21 am    Post subject: Reply with quote

Yeah, I was doing that from memory instead of looking at the API. What happens is you move a video event and the first frame can change by that distance. So you save the offset (how far from the beginning the first frame really is), move the event, and then reset the offset back to where it originally was.

Try:

trackEvent.ActiveTake.Offset
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Thu Nov 01, 2007 12:23 am    Post subject: Reply with quote

Back to this:
Code:

Effect CreateTransitionEffect(Vegas vegas, String plugInName) {  //TWO ARGUMENTS
    PlugInNode plugIn = vegas.Transitions.GetChildByName(plugInName);
    if (null == plugIn)
        throw new ApplicationException(String.Format("Failed to find plug-in: '{0}'", plugInName));
    return new Effect(plugIn);
}


Effect fadeInTx = CreateTransitionEffect("Sony Dissolve");  //ONE ARGUMENT
videoEvent.FadeIn.Transition = fadeInTx;
fadeInTx.Preset = "Additive Dissolve";
Effect fadeOutTx = CreateTransitionEffect("Sony Slide");
videoEvent.FadeOut.Transition = fadeOutTx;
fadeOutTx.Preset = "Additive Dissolve";


I cant get this to work at all. C# keeps telling me that this line: vegas.Transitions.GetChildByName(plugInName); has an error: "The name 'vegas' does not exist in the current context". I've changed it to everything I could think of with no luck.


Is there any better Sony documentation or books other than the API FAQ and API Scripting Summary?

Thanks.
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Thu Nov 01, 2007 2:34 am    Post subject: Reply with quote

Freddie, I'd need to see the rest of the code. How big is the entire thing? Either post the whole thing here or e-mail it to me.
Back to top
View user's profile Send private message Send e-mail
Freddie



Joined: 10 Mar 2006
Posts: 100

PostPosted: Thu Nov 01, 2007 4:47 pm    Post subject: Reply with quote

Thanks Ed,

Referencing the code below, what I really need is to add a Flash transition in between the two trackEvents. I tried using a sample from the Sony API FAQ but I've now abandoned that approach. I'm not sure how to do this. Can you get me started? Thanks.

Code:

// Sony Vegas C# Script
// Moves selected track event to start at the end of the previous track event - :10 seconds.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;


namespace VegasMoveEvent
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
            TrackEvent priorEvent;
            priorEvent = null;

            Timecode overlap = new Timecode("00:00:00.10");   

            foreach (Track track in vegas.Project.Tracks)
            {
                foreach (TrackEvent trackEvent in track.Events)
                {
                    if (trackEvent.Selected)
                    {
                        if (trackEvent.Index == 0)
                        {
                            MessageBox.Show("First Event Not Allowed!!");
                        }
                        else
                        {
                            trackEvent.Start = priorEvent.End - overlap;
                            //ADD FLASH TRANSITION HERE <---------------------------
                        }
                    }
                    else
                    {
                        priorEvent = trackEvent;
                    }

                }
            }
        }
    }
}

Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Thu Nov 01, 2007 5:09 pm    Post subject: Reply with quote

Try this:

Code:
// Sony Vegas C# Script
// Moves selected track event to start at the end of the previous track event - :10 seconds.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;


namespace VegasMoveEvent
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
            TrackEvent priorEvent;
            priorEvent = null;

            Timecode overlap = new Timecode("00:00:00.10");   

            foreach (Track track in vegas.Project.Tracks)
            {
                foreach (TrackEvent trackEvent in track.Events)
                {
                    if (trackEvent.Selected)
                    {
                        if (trackEvent.Index == 0)
                        {
                            MessageBox.Show("First Event Not Allowed!!");
                        }
                        else
                        {
                            Timecode offset = trackEvent.ActiveTake.Offset;
                            trackEvent.Start = priorEvent.End - overlap;
                            trackEvent.ActiveTake.Offset = offset;

                            //ADD FLASH TRANSITION HERE <---------------------------
                            PlugInNode fx = vegas.Transitions;
                            PlugInNode plugIn = fx.GetChildByName("Sony Dissolve");
                            Effect effect = new Effect(plugIn);
                            trackEvent.FadeIn.Transition = effect;
                            effect.Preset = "Additive Dissolve";
                        }
                    }
                    else
                    {
                        priorEvent = trackEvent;
                    }

                }
            }
        }
    }
}



p.s. I also included by other "offset" fix as well.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group