Comments

jetdv wrote on 12/16/2004, 9:20 AM
When rendering, you can specify the starting and ending timecodes. How are you rendering from the script now? When making the rendering call you can also specify the beginning and ending timecode.
hdguru wrote on 12/16/2004, 11:06 AM
For my end goal, I think that I will actually need to trim the clip. Is that possible through scripting in Vegas? I have a large amount of footage stored on a network. If I received an "order" from a user containing filenames and timecodes, Would I be able to compile one custom scene from various files, using the time codes given by the user? Maybe even apply transition effects from one trimmed clip to another for the final custom scene.

I would need to:

-Load a file
-Trim using timecodes specified by user
-load second file
-Trim using timecodes specified by user
-"butt" the second file right after the first
-Continue untill custom scene is completed
-Render

I have written scripts for various Adobe products which enables users to generate custom graphics from easy to use web interfaces. I was upset to learn the Premier does not support scripting. If Vegas can do what I would like to do through scripting, my company will definitely be making the switch.


Thanks
jetdv wrote on 12/16/2004, 11:11 AM
Vegas can definitely do the above via scripting.
hdguru wrote on 12/16/2004, 12:11 PM
Great. I actually have most of it down. Can you point me to the part of the documentation that deals with trimming the media in the timeline? The method I would be dealing with.
jetdv wrote on 12/16/2004, 12:32 PM
Look up AdjustStartLength in the API
hdguru wrote on 12/16/2004, 2:53 PM
Thanks. One more thing.

I'm creating a js file. You can't just double click on it to execute the script? Is it really necessary to open the vegas interface and select the script from the menu? Are there any work arounds?
rcampbel wrote on 12/16/2004, 5:53 PM
This link shows how to start Vegas and launch a script from the command line.
hdguru wrote on 12/18/2004, 9:41 AM
Thanks for the info. I can't seem to get the AdjustStartLength to work. I get a type mismatch error with the following code. I thought it should work, since I'm applying the method to the selected event. Here's the section that's giving me trouble. I get a Type mismatch on the AdjustStartLength line. Any pointers would be greatly appreciated. Thanks.

import System;
import System.IO;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

for (var t in Vegas.Project.Tracks) {
for (var e in t.Events)
{
e.Selected = true;
e.AdjustStartLength(0,200000,false);

}
}
jetdv wrote on 12/18/2004, 12:22 PM
The parameters need to be timecodes. Try this instead:

e.AdjustStartLength(new Timecode(0), new Timecode(200000), false);
hdguru wrote on 12/18/2004, 3:19 PM
Thanks, you are very helpful. I thought e.Start(new Timecode(0)); should move the selected event to the beginning of the track. It doesn't seem to do it though. It doesn't give any errors, but the event doesn't move either.

for (var t in Vegas.Project.Tracks) {
for (var e in t.Events){
e.Selected = true;
e.AdjustStartLength(new Timecode(30000), new Timecode(90000), false);
e.Start(new Timecode(0));
}
}
jetdv wrote on 12/18/2004, 7:48 PM
How about:

e.Start = new Timecode(0);

You may need to adjust the offset as well after moving it.
hdguru wrote on 12/19/2004, 8:43 AM
"You may need to adjust the offset as well after moving it."

Would you mind expounding on that?

The code does trim the event as intended, but once I try to move the event to the beginning of the timeline via the e.Start = new Timecode(0);, the event is no longer trimed the same way. Is there a way to just move the event with the trim remaining in tact? Thanks again.
jetdv wrote on 12/19/2004, 10:52 AM
That's why I said you would need to adjust the offset as well. Here's what you really need to do:

var currTake = e.ActiveTake;
var currOffset = currTake.Offset;
e.Start = new Timecode(0);
currTake.Offset = currOffset;

This will reset the offset back to the correct place AFTER the event has been moved.
hdguru wrote on 12/24/2004, 6:17 AM
I finished!

The code could probably be more efficient, but it works. Thanks so much for your help jetdv. I will post my code. It might be helpful to a beginner in the future. I do have one more question. If I wanted to overlap two segments on the timeline and apply a transition to the overlapping region, how would I apply the transition? I'm not asking for the code, if you could just point me in the right direction. Here's my code that will loop through an array of file paths and timecodes, and trim and arrange each clip. I still need to add the code to render at the end.

Begin amateur Code:

import System;
import System.IO;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

var arrClipInfo : Array;
arrClipInfo = [ ["D:\\Clip1.m2t", "00:00:30:00" , "00:00:60:00"],
["D:\\Clip2.m2t", "00:00:30:00" , "00:00:40:00"],
["D:\\Clip3.m2t", "00:00:10:00" , "00:00:20:00"]];

var Moveto = new Timecode(0);
for(var i=0; i<arrClipInfo.length; i++){

var path = arrClipInfo[i][0];

Vegas.OpenProject(path);
var Count = 0;

for (var t in Vegas.Project.Tracks) {

for (var e in t.Events){
if (e.Index == i){
var thisClipLength = e.Length;
var TrimStart = new Timecode(arrClipInfo[i][1]);
var TrimEnd = new Timecode(arrClipInfo[i][2]);
e.Selected = true;

if (i == 0){
var ClipLength = e.Length;
e.AdjustStartLength(TrimStart, TrimEnd, false);
}else{
e.AdjustStartLength(ClipLength + TrimStart, TrimEnd, false);
}


var currTake = e.ActiveTake;
var currOffset = currTake.Offset;

if (i != 0 && Count == 0){
Moveto = Moveto + TrimEnd;
}

e.Start = new Timecode(Moveto);
currTake.Offset = currOffset;


if (i != 0 && Count != 0){
ClipLength = ClipLength + thisClipLength;
}

e.Selected = false;
}
}
Count++;
}

}
jetdv wrote on 12/24/2004, 12:04 PM
To apply a transition, apply it to the fade-in as an effect. Here's the general method:

var fx = Vegas.Transitions;
var plugIn = fx.GetChildByName(plugInName);

var effect = new Effect(plugIn);
MyEvent.FadeIn.Transition = effect;
effect.Preset = presetName;

Naturally plugInName and presetName have to be defined as the desired transition.