Scripting Challenge

murk wrote on 1/18/2003, 12:20 PM
CHALLENGE:

Use VV4's scripting features to create a 1 (more preferrably variable) second transition between every event in a track. Each transition should be chosen at random.

EXAMPLE: Drag a folder of 100 still images into a track. No transistions or event overlaps are present. Apply the script, now every event is overlapped 1 second with a random trantion.

I have no prize offering, but the person that does it is well on their way to VV4 scripting Nirvana...

Comments

Control_Z wrote on 1/18/2003, 7:20 PM
Of course, using that many different transitions would be the mark of a true amateur, but if the script allowed you to input a fancy transition every x transitions that would be nice.

I wrote something like this for our Video Toaster a while back. I look forward to seeing some info about this scripting language.

Actually, I remember now random transitions didn't work because some I just didn't like. I had to use a text file with a list of acceptable transitions.
wcoxe1 wrote on 1/18/2003, 7:30 PM
There are only a few transitions that I find normally useful. How about this idea. A script the user loads with ACCEPTALBE transitions, and that when run, stops at each event intersection, waits until you press a number from that LIST of acceptable (to YOU) transitions, and then goes to the next one and waits for another keypress. In other words, a simple loop with choice menu.
murk wrote on 1/19/2003, 4:25 PM
These are good ideas too, but we must start with basic functionality before we start thinking about more gandiose scripts. I think the scripting ability of VV4 is amazingly powerful.

With most COM objects, you can just browse the API to figure out how to use it. VV4 uses the .NET architecture for scripting. I am new to .NET and haven't figured out how to browse an object's API yet.
SonyEPM wrote on 1/20/2003, 9:45 AM
If you have the V4 beta, try this:

1) Toss a bunch of still on the timeline- this will create a string of new events.

2) Select all of these new events

3) Drag any transition preset from the "transitions" pane to any cut point, and drop it. The traansition is added to all of the selected events.

Transition length is defineable in editing prefs: cut to ovelap transition.
TomHHI wrote on 1/20/2003, 10:41 AM
I have been using VF to produce videos for a group of WWII destroyer veterans, based on stills. Have been considering upgrading to Vegas. This is the icicng on the cake.
Summersond wrote on 1/20/2003, 12:41 PM
Sonic, I think burstingfist was wanting to do exactly what you are describing, but with the flexibility to have a random transistion inserted at each transistion point rather than one manually picked by him. Could this be a check box in editting preferences located by the transistion length selection? The software would just choose a random trans. and insert it when a group of events were selected.

my 2 cents worth...
dave
murk wrote on 1/22/2003, 12:27 AM
Ok, here's the script. The VV4 object model is rich indeed. This will be a great way to add functionality to VV4. Thanks to Paul Manly of Sonic Foundry Engineering for helping with a crucial piece of code. This is just the beginining. With scripting the sky is the limit. No other NLE has a COM based engine that is this complete and easy to use.

/**
* Save this text as ApplyTransitions.js
*
* Apply Transition to Adjacent Video events and optionally move
* events to overlap events.
*
* For use with Sonic Foundry Vegas Video 4.0
*
* Copyright 2002 murkWare (mj@sightworks.com)
**/
import System.Windows.Forms;
import SonicFoundry.Vegas.Script;
var overlapTime = 1000;

var dialog = new TransitionDialog(overlapTime);
var bFade = false; //Only true if the second list item is chosen
var bRandom = false; //Only true if the first list item is chosen
dialog.m_transList.Items.Add("Random For each event")
dialog.m_transList.Items.Add("Standard Cross Fade")
var count = 0;
var totalTrans = Vegas.Transitions.Count;
var num;
var transEnum = new Enumerator(Vegas.Transitions);
while (!transEnum.atEnd())
{
var trans = transEnum.item();
if(count > 0)
dialog.m_transList.Items.Add(trans.Name);
count++;

transEnum.moveNext();
}
try
{
dialog.m_transList.SelectedIndex = 0
var dialogResult = dialog.ShowDialog();
var iTrans = int(dialog.m_transList.SelectedIndex);
if(System.Windows.Forms.DialogResult.OK == dialogResult)
{
if (iTrans == 0)
{
bRandom = true;
}
else if(iTrans == 1)
{
bFade = true
}

var plugIn;
if(iTrans > 1)
{
plugIn = Vegas.Transitions.GetChild(int(iTrans -1));
}

overlapTime = int(dialog.overlapTimeBox.Text);
var startoffset = overlapTime;
var trackEnum = new Enumerator(Vegas.Project.Tracks);
var fx;

while (!trackEnum.atEnd())
{
var tr = trackEnum.item();
var eventEnum = new Enumerator(tr.Events);

while (!eventEnum.atEnd())
{
var ev = eventEnum.item();

ev.FadeIn.Curve = CurveType.Slow
if(bRandom)
{
num = int(Math.random() * totalTrans + 1);
if (num > 23)
{
num = totalTrans - 1;
}
plugIn = Vegas.Transitions.GetChild(int(num));
}


var startTime = new Timecode(ev.Start);
var length = new Timecode(ev.Length);
startTime.Subtract(startoffset);
ev.AdjustStartLength(startTime,length,true);
Vegas.UpdateUI();
if(ev.MediaType == MediaType.Video && !bFade)
{
fx = new Effect(plugIn);
ev.FadeIn.Transition = fx;
}
eventEnum.moveNext();
startoffset = startoffset + overlapTime;
}
startoffset = overlapTime;
trackEnum.moveNext();
}
}
} catch (e)
{
MessageBox.Show(e + "\n\nReport this error to mj@sightwork.com\n\n" + num);
}
// Form subclass that is the dialog box for this script
class TransitionDialog extends Form {

var overlapTimeBox;
var m_transList;

function TransitionDialog(overlapTime) {
this.Text = "Add Transitions to adjacent events";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.Width = 480;
this.Height = 120;

var buttonWidth = 80;
var buttonHeight = 24;
var buttonTop = 60;

overlapTimeBox = addTextControl("Overlap Time (ms)", 320, 140, 20, overlapTime.ToString());
m_transList = addComboBox(20,80,20);

var okButton = new Button();
okButton.Text = "OK";
okButton.Left = this.Width - ((buttonWidth+10));
okButton.Top = buttonTop;
okButton.Width = buttonWidth;
okButton.Height = buttonHeight;
okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
AcceptButton = okButton;
Controls.Add(okButton);

var label = new Label();
label.AutoSize = true;
label.Text = "Copyright 2003 murkWare"
label.Left = 20;
label.Top = 80;
Controls.Add(label);
}

function addTextControl(labelName, left, width, top, defaultValue) {
var label = new Label();
label.AutoSize = true;
label.Text = labelName + ":";
label.Left = left;
label.Top = top + 4;
Controls.Add(label);

var textbox = new TextBox();
textbox.Multiline = false;
textbox.Left = label.Right;
textbox.Top = top;
textbox.Width = width - (label.Width);
textbox.Text = defaultValue;
Controls.Add(textbox);

return textbox;
}

function addComboBox(left,width,top)
{

var transList = new ComboBox();

// transList.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
// Or System.Windows.Forms.AnchorStyles.Right)
transList.DropDownWidth = width;
// transList.Items.AddRange(tem 5"});
transList.Location = new System.Drawing.Point(left, top);
transList.Size = new System.Drawing.Size(280, 21);
transList.TabIndex = 7;
Controls.Add(transList);

return transList;
}

}
snicholshms wrote on 1/22/2003, 12:49 AM
This is unreal. Have to ask the obvious question...
Where do we modify and what do we type in to this script to
1. Select a specific transition for all; 2. Select NO transitions, just a simple crossfade.

Should have taken programming in college back in 1968...oh yeah, they didn't offer it!
murk wrote on 1/22/2003, 1:23 AM
The script pops up a dialog box that allows you to choose either a random transition, a simple cross fade or a specific transition. It also allows you to specify how much to overlap the events.
murk wrote on 1/22/2003, 1:48 AM
Thanks Sonic, I knew there was some way to this. I went ahead and built the script anyway. It allows for a little more options than the built VV4 functionality.
kirkdickinson wrote on 1/22/2003, 12:47 PM
I tried to play with it and got an error saying "Could not initialize script engine"

What did I do wrong?

Kirk
bcbarnes wrote on 1/22/2003, 1:03 PM
Burstingfist,

Where did you get the information on how to use the Vegas API?
murk wrote on 1/22/2003, 6:15 PM
I reverse engineered it using Microsoft .NET Studio. I created a new VB .NET applicaion solution and added a reference to SonicFoundry.ScriptHost.dll in the Vegas 4.0 directory. Then when I use any objects, .NET studio provides a popup of all methods and properties. Sonic Foundry built the object model very well so thet it is intuitive to use.
murk wrote on 1/22/2003, 6:17 PM
In order to use the scripting features of VV4, you must have all of the latest Microsoft .NET stuff installed. just type in 'windowsupdate' in google and the top link should take you right to where you update your machine with the latest recommended updates.
taliesin wrote on 1/22/2003, 6:59 PM
Wow, cool!!!

It really works like a charm :-)

Are we allowed to share it with other people?

Marco
Luxo wrote on 1/22/2003, 7:08 PM
Dude! You are the man! And truly random -- apply the script, undo, apply again and you get entirely different transitions. Now how about implimenting the above suggestions: ability to select approved transitions and crossfade for x transitions, then apply a random or approved transition.

I can't believe how fast the script is too. After trying the export as stills one, I thought they'd all run at a snail's pace. Stellar work!

Luxo
eheh wrote on 1/22/2003, 9:11 PM
Please share the VB.NET code
CraigF wrote on 1/23/2003, 9:33 AM
This functionality is what a co-worker has been looking for. It may be enough to sell him on vegas 4.... :)

So where's the SDK for the people who don't have .NET Studio?


Craig
CraigF wrote on 1/23/2003, 2:19 PM
How about the Vegas 4 SDK...so we don't have to reverse engineer anything. :)

Craig
wcoxe1 wrote on 1/23/2003, 2:37 PM
Someone, above, metioned that you needed to upgrade your Windows to all the latest and greatest .NET stuff.

However, do you need to have the JavaScrip, Java, or Visual Basic LANGUAGE to use these scripts? That would be a REAL let down.
CraigF wrote on 1/23/2003, 3:05 PM
**Quote***
Someone, above, metioned that you needed to upgrade your Windows to all the latest and greatest .NET stuff.

However, do you need to have the JavaScrip, Java, or Visual Basic LANGUAGE to use these scripts? That would be a REAL let down.
****End Quote***

All you need is .NET Framework to interface with Vegas, and the knowledge to right scripts. Since we are talking Java Script or VB script, you don't need software to write them, as they are not compiled programs.

The SDK that I was talking about has now been posted on the V4 downloads page. It is a simple reference guide of the Vegas API.

I say simple...because it is an HTML page with the functions and an explaination. In know way am I implying that writing the scripts is simple. I'm simply handing this stuff over to a friend who KNOWS how to code...I can only read it.

Craig
eheh wrote on 1/24/2003, 11:40 PM
Can one simply reference to the scripting host and write a VB.NET (for example) code that uses services from Vegas?
shaunn wrote on 1/26/2003, 2:29 PM
Burstingfist:

Your Script is really neat for randomness but would it be possible for the script to go through "all" of the transitions ?
Right now, it is setup to randomize the first transition of the the different type of transition style. For example in "page peel" only "top left medium fold" is used and in "linear wipe" - "top left diagonal soft edge" and so on etc,,,

Thanks

Shaun