RenderQueue w/ multiple templates, little interaction

dcornewell wrote on 7/24/2003, 11:17 AM
I don't know if anyone is as lazy as I am, but I want any repetitive steps in rendering to go away. RenderQueue.js was nice, but I use more than one template to render video with. I also use a computer in my basement to render video. VNC is slow, remote desktop doesn't seem to work in 4.0c, and I'm not going to walk all the way down there.

So, I wrote a new script. I call it RenderQueue_Auto.js. Basically, it has an array of source directories it checks for .veg files. Each dir represents a template. The templates are set up in another array. When it finds a .veg file, it renders it using the appropriate template. Just make sure to transfer the media THEN the .veg file.

It has a timer that counts down from 10. When it hits 0, it checks the dirs again. While it is rendering something the timer stops. This is not done, but it does work. I want to get rid of the timer and rely completely on events. There is a pending listview that currently does not do anything also.

//------ Begin File RenderQueue_Auto.js ------
// Written by: David Cornewell
// Email: dcornewell@comcast.net
// Date: July 22, 2003
// Based partially on RenderQueue.js that was
// Packaged with SonicFoundry's Video Vegas 4.0c
//
//

import System;
import System.IO;
//import System.ServiceProcess;
//import System.Diagnostics;
import System.Timers;
import System.Windows.Forms;
import System.ComponentModel;
import System.Drawing;
import SonicFoundry.Vegas;

//I use the same renderer so I won't put it in an array
var rendererRE = /Windows Media Video V9/;

//Add items to the arrays to specify a dir to check for project files (.veg)
// It will use the appropriate template to render the file
var InputDirs = new Array();
var Templates = new Array();

InputDirs[0] = "E:\\Movies\\To Encode\\movie\\"; Templates[0] = /Movie/;
InputDirs[1] = "E:\\Movies\\To Encode\\Cartoon86\\"; Templates[1] = /Cartoon86/;
InputDirs[2] = "E:\\Movies\\To Encode\\Cartoon90\\"; Templates[2] = /Cartoon90/;
InputDirs[3] = "C:\\"; Templates[3] = /Test/;
//InputDirs[3] = "E:\\Movies\\To Encode\\\\"; Templates[3] = ;
var num_encode_dirs=4;

// Set this to a valid out directory or set it to null if you want the
// output files to be created in the same directory as their project
// file.
var defaultOutputDir = null;

// Set the following variable to true if you want to allow the script
// to overrwite existing rendered output files.
var allowFileOverwrites = true;

var iPauseSec: int = 10;

package VegasRenderMachinePkg {
// class ClickPanel extends System.Windows.Forms.Panel {
// override protected function OnMouseUp (e : MouseEventArgs) {
// super.OnMouseUp(e);
// MessageBox.Show("Mouse Up at: "+e.X+", "+ e.Y);
// }
// }

class VegasRenderMachineCls extends System.Windows.Forms.Form {
private var lblPending, lblDone, lblTimer, lblError: Label;
private var listBoxR, listBoxError: ListBox;
private var listViewPending: ListView;
private var textBoxTimer: TextBox;
private var btnStart: Button;
private var btnStop: Button;
// private var btnExit: Button;
private var basePanel, bottomPanel, leftPanel, rightPanel: Panel;
// private var rightPanel: ClickPanel;
private var localTimer : System.Timers.Timer ;

function btnStart_Clicked(o : Object, e : EventArgs) {
// bottomPanel.textBoxTimer.Text = "5";
localTimer.Enabled = true;
}
function btnStop_Clicked(o : Object, e : EventArgs) {
localTimer.Enabled = false;
}

function btnExit_Clicked(o : Object, e : EventArgs) {
// VegasRenderMachineCls.Exit();
}

function OnTimer( source:Object, e: ElapsedEventArgs )
{
var i: int = Convert.ToInt32(textBoxTimer.Text);

i--;
if(i<0) {
textBoxTimer.Text=Convert.ToString(iPauseSec);
localTimer.Enabled=false;
RenderMachine();
localTimer.Enabled=true;
} else {
textBoxTimer.Text = Convert.ToString(i);
}
}

function VegasRenderMachineCls() {
this.Text= "Rending Jobs";
this.ClientSize= new System.Drawing.Size(500,300);
this.StartPosition= System.Windows.Forms.FormStartPosition.CenterScreen;

basePanel= new Panel;
basePanel.Location= new Point(0,0);
basePanel.Size= new System.Drawing.Size(500,300);
basePanel.Name= "basePanel";
basePanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;

leftPanel= new Panel;
leftPanel.Location= new Point(0,0);
leftPanel.Size= new System.Drawing.Size(250,250);
leftPanel.Name= "leftPanel";
leftPanel.Dock= DockStyle.Left;
leftPanel.BorderStyle = "Fixed3D";

lblPending = new Label;
lblPending.Location= new Point(100,0);
lblPending.Size= new System.Drawing.Size(50,15);
lblPending.Name= "lblPending";
lblPending.Text= "Pending:";
lblPending.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(lblPending);

listViewPending = new ListView;//Box;
listViewPending.View = View.Details;
listViewPending.GridLines = true;
listViewPending.AllowColumnReorder = true;
listViewPending.Columns.Add("Project Name", -2, HorizontalAlignment.Left);
listViewPending.Columns.Add("Path", -2, HorizontalAlignment.Left);
listViewPending.Location= new Point(3,15);
listViewPending.Size = new System.Drawing.Size(240,155);
listViewPending.Name= "listViewPending";
listViewPending.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(listViewPending);

lblError = new Label;
lblError.Location= new Point(100,169);
lblError.Size= new System.Drawing.Size(40,15);
lblError.Name= "lblError";
lblError.Text= "Errors:";
lblError.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(lblError);

listBoxError = new ListBox;
listBoxError.Location= new Point(3,184);
listBoxError.Size = new System.Drawing.Size(240,60);
listBoxError.Name= "listBox1";
// listBoxError.Items.Add();
listBoxError.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(listBoxError);

rightPanel= new Panel; //ClickPanel
rightPanel.Location= new Point(250,0);
rightPanel.Size= new System.Drawing.Size(250,250);
rightPanel.Name= "rightPanel";
rightPanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
rightPanel.BorderStyle = "Fixed3D";

lblDone = new Label;
lblDone.Location= new Point(90,0);
lblDone.Size= new System.Drawing.Size(35,15);
lblDone.Name= "lblDone";
lblDone.Text= "Done:";
lblDone.Anchor= AnchorStyles.Left | AnchorStyles.Top;
rightPanel.Controls.Add(lblDone);

listBoxR = new ListBox;
listBoxR.Location= new Point(3,15);
listBoxR.Size = new System.Drawing.Size(240,230);
listBoxR.Name= "listBox1";
// listBoxR.Items.Add();
listBoxR.Anchor= AnchorStyles.Left | AnchorStyles.Top;
rightPanel.Controls.Add(listBoxR);

bottomPanel= new Panel;
bottomPanel.Location= new Point(0,250);
bottomPanel.Size= new System.Drawing.Size(500,50);
bottomPanel.Name= "bottomPanel";
bottomPanel.Anchor= AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
bottomPanel.BorderStyle = "Fixed3D";

btnStart= new Button;
btnStart.Location= new Point(190,15);
btnStart.Size= new System.Drawing.Size(50,20);
btnStart.Name= "btnStart";
btnStart.Text= "Start";
btnStart.Anchor= AnchorStyles.Left;
bottomPanel.Controls.Add(btnStart);
btnStart.add_Click(btnStart_Clicked);

btnStop= new Button;
btnStop.Location= new Point(255,15);
btnStop.Size= new System.Drawing.Size(50,20);
btnStop.Name= "btnStop";
btnStop.Text= "Stop";
btnStop.Anchor= AnchorStyles.Left;
bottomPanel.Controls.Add(btnStop);
btnStop.add_Click(btnStop_Clicked);

// btnExit= new Button;
// btnExit.Location= new Point(350,15);
// btnExit.Size= new System.Drawing.Size(60,20);
// btnExit.Name= "btnExit";
// btnExit.Text= "Exit";
// btnExit.Anchor= AnchorStyles.Left;
// bottomPanel.Controls.Add(btnExit);
// btnExit.add_Click(btnExit_Clicked);

localTimer = new System.Timers.Timer();
localTimer.Interval=1000;
localTimer.AutoReset=true
localTimer.add_Elapsed(OnTimer);
localTimer.Enabled=true;

lblTimer = new Label;
lblTimer.Location= new Point(5,15);
lblTimer.Size= new System.Drawing.Size(115,20);
lblTimer.Name= "lblTimer";
lblTimer.Text= "Time to Next Check:";
lblTimer.Anchor= AnchorStyles.Left | AnchorStyles.Top;
bottomPanel.Controls.Add(lblTimer);

textBoxTimer = new TextBox;
textBoxTimer.Location= new Point(120,13);
textBoxTimer.Size = new System.Drawing.Size(20,20);
textBoxTimer.Name= "textBoxTimer";
textBoxTimer.Text = Convert.ToString(iPauseSec);
textBoxTimer.Anchor= AnchorStyles.Left | AnchorStyles.Top;
bottomPanel.Controls.Add(textBoxTimer);

basePanel.Controls.Add(rightPanel);
basePanel.Controls.Add(bottomPanel);
basePanel.Controls.Add(leftPanel);

this.Controls.Add(basePanel);

}

function RenderMachine()
{
var fc;
var ext;
var i;

if ((null != defaultOutputDir) && !Directory.Exists(defaultOutputDir)) {
SendError("output directory does not exist: " + defaultOutputDir);
return;
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

for (i=0; i<num_encode_dirs; i++) {
if (Directory.Exists(InputDirs[i])) {
fc = GetFolderFileList(InputDirs[i]);
for (; !fc.atEnd(); fc.moveNext())
{
ext = fso.GetExtensionName(fc.item());
if (ext == "veg") {

// var item1:ListViewItem = new ListViewItem(Path.GetFileNameWithoutExtension(fc.item()),0);
// item1.Checked = false;
// item1.SubItems.Add(InputDirs[i] + fc.item());
// listViewPending.Items.Add(item1);

var renderStatus = RenderProject(fc.item(), rendererRE, Templates[i]);
if (RenderStatus.Complete == renderStatus) {
listBoxR.Items.Add(Path.GetFileNameWithoutExtension(fc.item()));
fso.MoveFile(fc.item(), fc.item()+".done");
Vegas.NewProject();
} else {
SendError("failed to complete render: " + fc.item());
return;
}
}
//MessageBox.Show(fc.item());
}
}
}

}

function RenderProject(vegFilename, rendererName, TemplateName)
{
if (!Vegas.OpenProject(vegFilename)) {
throw "failed to open project file: " + vegFilename;
}

// find the renderer and template
var renderer : Renderer = FindRenderer(rendererName);
if (null == renderer) {
SendError("failed to find renderer " + rendererName);
return;
}

var renderTemplate :RenderTemplate = FindRenderTemplate(renderer, TemplateName);
if (null == renderTemplate) {
SendError("failed to find render template " + TemplateName);
return;
}

// get file name extension that will be appended to each output file
var rendererExt = renderer.FileExtension.substring(1);

// compute the output directory
var outputDir;
if (null == defaultOutputDir) {
outputDir = Path.GetDirectoryName(vegFilename);
} else {
outputDir = defaultOutputDir;
}

// create the output file name
var outputName = Path.GetFileNameWithoutExtension(vegFilename);
var outputFilename = outputDir + Path.DirectorySeparatorChar + outputName + rendererExt;
if ((!allowFileOverwrites) && File.Exists(outputFilename)) {
SendError("file already exists: " + outputFilename);
return;
}

// perform the render
var renderStatus = Vegas.Render(outputFilename, renderTemplate);
return renderStatus;
}

// Hopefully this will get me a list of stuff
function GetFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
return(fc);
}

function FindRenderer(rendererRegExp : RegExp) : Renderer {
var rendererEnum : Enumerator = new Enumerator(Vegas.Renderers);
while (!rendererEnum.atEnd()) {
var renderer : Renderer = Renderer(rendererEnum.item());
if (null != renderer.FileTypeName.match(rendererRegExp)) {
return renderer;
}
rendererEnum.moveNext();
}
return null;
}

function FindRenderTemplate(renderer : Renderer, templateRegExp : RegExp) : RenderTemplate {
var templateEnum : Enumerator = new Enumerator(renderer.Templates);
while (!templateEnum.atEnd()) {
var renderTemplate : RenderTemplate = RenderTemplate(templateEnum.item());
if (renderTemplate.Name.match(templateRegExp)) {
return renderTemplate;
}
templateEnum.moveNext();
}
return null;
}

function SendError(message)
{
localTimer.Enabled = false; //stop process
listBoxError.Items.Add(message); // put error into list
return;
}

}
}

try {
Application.Run(new VegasRenderMachinePkg.VegasRenderMachineCls());
} catch (E) {
throw (E);
}


//------ End File RenderQueue_Auto.js ------

Comments

SonyPJM wrote on 7/24/2003, 1:17 PM
Very nice!

Hopefully what we're working on now (for a future release) will be what you need to get rid of the timer and rely on events.
dcornewell wrote on 7/24/2003, 2:50 PM
I was planning on using a FileSystemWatcher. I just haven't read the documentation on it. A co-worker told me about it after I had done the timer. I'm used to coding in linux so this a little new.

Can I ask what you are working on for this future release?
SonyPJM wrote on 7/25/2003, 8:11 AM
The FileSystemWatcher is a good plan but I think the trick will be
using it in conjunction with a Vegas script. Currently, scripts run
synchronously within Vegas and any objects created by a script go away
once the script completes. So if the script blocks to wait for
something, Vegas is hung too and in some cases can't even redraw its
window(s). If you want to avoid hanging Vegas, you'll need an
external app that handles the FileSystemWatcher events by sending
Vegas "Run Script" messages or by launching Vegas with a -SCRIPT
command line argument.

One goal (not promise) for a future release is to allow scripts to
run asynchronously within Vegas and have them be able to respond to
events from within Vegas and elsewhere as needed. I use the term
asynchronous loosely here, scripts likely will still need to run on
Vegas' main thread but they'll be able to stick around and respond
when other things happen.

This will hopefully allow for scripted "editors" with GUIs that can be
docked along side the existing views like the trimmer, explorer, media
pool, etc.
dcornewell wrote on 7/25/2003, 12:05 PM
Well, I had a slow day at work, so I decided to get rid of the timer. VV seems to redraw just fine when my app is running. I am threading the function that calls Vegas.Render() so things can be added to the Pending list while it is rendering. I need to read up so I know which objects I need to destroy.(like threads?) I have heard that .net code is more 'managed' than what I am used to. Any criticism will be welcome.

Next I might make the Pending list editable so the template can be changed and items can be re ordered.

I think that being able to dock this app would be very cool! Are you sure there isn't a way to do that now? If not, put my vote in to get it in the next release. Even to be able to create a button that hides/shows a form I create would be mildly amusing.

// -----Start File

// Written By: David Cornewell
// Email: dcornewell @comcast.net
// Date: July 22, 2003
// Based partially on RenderQueue.js that was
// packaged with SonicFoundry's Video Vegas 4.0c
//
//

import System;
import System.IO;
import System.Threading
import System.Windows.Forms;
import System.ComponentModel;
import System.Drawing;
import SonicFoundry.Vegas;

//I use the same renderer so I won't put it in an array
var rendererRE = /Windows Media Video V9/;

//Add items to the arrays to specify a dir to check for project files (.veg)
// It will use the appropriate template to render the file
var InputDirs = new Array();
var Templates = new Array();

InputDirs[0] = "E:\\Movies\\To Encode\\movie\\"; Templates[0] = "Movie";
InputDirs[1] = "E:\\Movies\\To Encode\\Cartoon86\\"; Templates[1] = "Cartoon86";
InputDirs[2] = "E:\\Movies\\To Encode\\Cartoon90\\"; Templates[2] = "Cartoon90";
InputDirs[3] = "C:\\"; Templates[3] = "Test";
//InputDirs[3] = "E:\\Movies\\To Encode\\\\"; Templates[3] = ;
var num_encode_dirs=4;


// Set this to a valid out directory or set it to null if you want the
// output files to be created in the same directory as their project
// file.
var defaultOutputDir = null;

// Set the following variable to true if you want to allow the script
// to overrwite existing rendered output files.
var allowFileOverwrites = true;

var iIsRendering: int = 0;

package VegasRenderMachinePkg {
class VegasRenderMachineCls extends System.Windows.Forms.Form {
private var lblPending, lblDone, lblTimer, lblError: Label;
private var listBoxError: ListBox;
private var listViewPending,listViewDone: ListView;
private var btnStart: Button;
private var btnStop: Button;
private var basePanel, bottomPanel, leftPanel, rightPanel: Panel;

function btnStart_Clicked(o : Object, e : EventArgs) {
if (iIsRendering==0) {
var bg : Thread = new Thread(RenderMachine);
bg.Start();
}
}
function btnStop_Clicked(o : Object, e : EventArgs) {
}

function listViewPending_Added(o : Object, e : EventArgs)
{
MessageBox.Show("changed");
return;
}

//
// Define the event handlers for FileSystemWatcher.
//
function OnFileCreated(source: Object, e : FileSystemEventArgs)
{
// MessageBox.Show("File changed: " + e.FullPath + " E.type " + e.ChangeType);
var item1:ListViewItem = new ListViewItem(Path.GetFileNameWithoutExtension(e.FullPath),0);
item1.Checked = false;
item1.SubItems.Add(GetTemplate4Dir(Path.GetDirectoryName(e.FullPath)));
item1.SubItems.Add(e.FullPath);
listViewPending.Items.Add(item1);
if (iIsRendering==0) {
var bg : Thread = new Thread(RenderMachine);
bg.Start();
}
}

function OnFileRenamed(source :Object, e :RenamedEventArgs)
{
// if the To file is a .veg, then use it. if from is, ignore
var ext = Path.GetExtension(e.FullPath);
if (ext == ".veg") {
var item1:ListViewItem = new ListViewItem(Path.GetFileNameWithoutExtension(e.FullPath),0);
item1.Checked = false;
item1.SubItems.Add(GetTemplate4Dir(Path.GetDirectoryName(e.FullPath)));
item1.SubItems.Add(e.FullPath);
listViewPending.Items.Add(item1);
if (iIsRendering==0) {
var bg : Thread = new Thread(RenderMachine);
bg.Start();
}
}
return;
}

function VegasRenderMachineCls() {
this.Text= "Rending Jobs";
this.ClientSize= new System.Drawing.Size(500,300);
this.StartPosition= System.Windows.Forms.FormStartPosition.CenterScreen;

basePanel= new Panel;
basePanel.Location= new Point(0,0);
basePanel.Size= new System.Drawing.Size(500,300);
basePanel.Name= "basePanel";
basePanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;

leftPanel= new Panel;
leftPanel.Location= new Point(0,0);
leftPanel.Size= new System.Drawing.Size(250,250);
leftPanel.Name= "leftPanel";
leftPanel.Dock= DockStyle.Left;
leftPanel.BorderStyle = "Fixed3D";

lblPending = new Label;
lblPending.Location= new Point(100,0);
lblPending.Size= new System.Drawing.Size(50,15);
lblPending.Name= "lblPending";
lblPending.Text= "Pending:";
lblPending.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(lblPending);

listViewPending = new ListView;//Box;
listViewPending.View = View.Details;
listViewPending.GridLines = true;
listViewPending.AllowColumnReorder = true;
listViewPending.Columns.Add("Project Name", -2, HorizontalAlignment.Left);
listViewPending.Columns.Add("Template", -2, HorizontalAlignment.Left);
listViewPending.Columns.Add("Path", -2, HorizontalAlignment.Left);
listViewPending.Location= new Point(3,15);
listViewPending.Size = new System.Drawing.Size(240,155);
listViewPending.Name= "listViewPending";
listViewPending.Anchor= AnchorStyles.Left | AnchorStyles.Top;
// listViewPending.add_Add(listViewPending_Added);
leftPanel.Controls.Add(listViewPending);

lblError = new Label;
lblError.Location= new Point(100,169);
lblError.Size= new System.Drawing.Size(40,15);
lblError.Name= "lblError";
lblError.Text= "Errors:";
lblError.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(lblError);

listBoxError = new ListBox;
listBoxError.Location= new Point(3,184);
listBoxError.Size = new System.Drawing.Size(240,60);
listBoxError.Name= "listBox1";
// listBoxError.Items.Add();
listBoxError.Anchor= AnchorStyles.Left | AnchorStyles.Top;
leftPanel.Controls.Add(listBoxError);

rightPanel= new Panel; //ClickPanel
rightPanel.Location= new Point(250,0);
rightPanel.Size= new System.Drawing.Size(250,250);
rightPanel.Name= "rightPanel";
rightPanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
rightPanel.BorderStyle = "Fixed3D";

lblDone = new Label;
lblDone.Location= new Point(90,0);
lblDone.Size= new System.Drawing.Size(35,15);
lblDone.Name= "lblDone";
lblDone.Text= "Done:";
lblDone.Anchor= AnchorStyles.Left | AnchorStyles.Top;
rightPanel.Controls.Add(lblDone);

listViewDone = new ListView;//Box;
listViewDone.View = View.Details;
listViewDone.GridLines = true;
listViewDone.AllowColumnReorder = true;
listViewDone.Columns.Add("Project Name", -2, HorizontalAlignment.Left);
listViewDone.Columns.Add("Template", -2, HorizontalAlignment.Left);
listViewDone.Columns.Add("Path", -2, HorizontalAlignment.Left);
listViewDone.Location= new Point(3,15);
listViewDone.Size = new System.Drawing.Size(240,230);
listViewDone.Name= "listViewPending";
listViewDone.Anchor= AnchorStyles.Left | AnchorStyles.Top;
rightPanel.Controls.Add(listViewDone);

bottomPanel= new Panel;
bottomPanel.Location= new Point(0,250);
bottomPanel.Size= new System.Drawing.Size(500,50);
bottomPanel.Name= "bottomPanel";
bottomPanel.Anchor= AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
bottomPanel.BorderStyle = "Fixed3D";

btnStart= new Button;
btnStart.Location= new Point(190,15);
btnStart.Size= new System.Drawing.Size(50,20);
btnStart.Name= "btnStart";
btnStart.Text= "Start";
btnStart.Anchor= AnchorStyles.Left;
bottomPanel.Controls.Add(btnStart);
btnStart.add_Click(btnStart_Clicked);

btnStop= new Button;
btnStop.Location= new Point(255,15);
btnStop.Size= new System.Drawing.Size(50,20);
btnStop.Name= "btnStop";
btnStop.Text= "Stop";
btnStop.Anchor= AnchorStyles.Left;
bottomPanel.Controls.Add(btnStop);
btnStop.add_Click(btnStop_Clicked);

//
// The filesystem Watcher is to notify me when files are added and need to be put in queue
// I might get delete,rename,etc to update the list. For now, i will NOT delete
//
var watcher :FileSystemWatcher= new FileSystemWatcher()
watcher.Path = InputDirs[3];
// Type of change to watch for (this code detects when
// new files appear in the directory)
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.IncludeSubdirectories = false;
watcher.Filter = "*.veg";
watcher.add_Created(OnFileCreated);
watcher.add_Renamed(OnFileRenamed);
watcher.EnableRaisingEvents = true;

//
// Put panels on base
//
basePanel.Controls.Add(rightPanel);
basePanel.Controls.Add(bottomPanel);
basePanel.Controls.Add(leftPanel);

RefreshPendingList();
this.Controls.Add(basePanel);

}

function RefreshPendingList()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");

listViewPending.Clear;
for (var i=0; i<num_encode_dirs; i++) {
if (Directory.Exists(InputDirs[i])) {
var fc = GetFolderFileList(InputDirs[i]);
for (; !fc.atEnd(); fc.moveNext())
{
var ext = fso.GetExtensionName(fc.item());
if (ext == "veg") {
var item1:ListViewItem = new ListViewItem(Path.GetFileNameWithoutExtension(fc.item()),0);
item1.Checked = false;
item1.SubItems.Add(Templates[i]);
item1.SubItems.Add(fc.item());

if (!listViewPending.Items.Contains(item1)) {
listViewPending.Items.Add(item1);
}
}
//MessageBox.Show(fc.item());
}
}
}
return;
}

function RenderMachine()
{
var fc;
var ext;
var fullpath;
var template;

iIsRendering=1;

if ((null != defaultOutputDir) && !Directory.Exists(defaultOutputDir)) {
SendError("output directory does not exist: " + defaultOutputDir);
return;
}

while (listViewPending.Items.Count > 0) {
var curritem = listViewPending.Items[0];

fullpath = curritem.SubItems[2].Text;
template = curritem.SubItems[1].Text;
if (File.Exists(fullpath)) {
Vegas.NewProject();
var renderStatus = RenderProject(fullpath, rendererRE, template);
if (RenderStatus.Complete == renderStatus) {
var item1:ListViewItem = new ListViewItem(curritem.SubItems[0].Text,0);
item1.Checked = false;
item1.SubItems.Add(curritem.SubItems[1].Text);
item1.SubItems.Add(curritem.SubItems[2].Text);
listViewDone.Items.Add(item1);
listViewPending.Items.Remove(curritem);
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.MoveFile(fullpath, fullpath+".done");
} else {
SendError("failed to complete render: " + fullpath);
return;
}
}

}
iIsRendering=0;

return;
}

function RenderProject(vegFilename, rendererName, TemplateName)
{
if (!Vegas.OpenProject(vegFilename)) {
SendError("failed to open project file: " + vegFilename);
}

// find the renderer and template
var rendererO : Renderer = FindRenderer(rendererName);
if (null == rendererO) {
SendError("failed to find renderer " + rendererName);
return;
}

var renderTemplate :RenderTemplate = FindRenderTemplate(rendererO, TemplateName);
if (null == renderTemplate) {
SendError("failed to find render template " + TemplateName);
return;
}

// get file name extension that will be appended to each output file
var rendererExt = rendererO.FileExtension.substring(1);

// compute the output directory
var outputDir;
if (null == defaultOutputDir) {
outputDir = Path.GetDirectoryName(vegFilename);
} else {
outputDir = defaultOutputDir;
}

// create the output file name
var outputName = Path.GetFileNameWithoutExtension(vegFilename);
var outputFilename = outputDir + Path.DirectorySeparatorChar + outputName + rendererExt;
if ((!allowFileOverwrites) && File.Exists(outputFilename)) {
SendError("file already exists: " + outputFilename);
return;
}

// perform the render
var renderStatus = Vegas.Render(outputFilename, renderTemplate);
return renderStatus;
}

function GetTemplate4Dir(dir)
{
for (var i=0; i<num_encode_dirs; i++) {
if (InputDirs[i] == dir) {
return Templates[i];
}
}
return null;
}

// Hopefully this will get me a list of stuff
function GetFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
return(fc);
}

function FindRenderer(rendererRegExp : RegExp) : Renderer {
var rendererEnum : Enumerator = new Enumerator(Vegas.Renderers);
while (!rendererEnum.atEnd()) {
var renderer : Renderer = Renderer(rendererEnum.item());
if (null != renderer.FileTypeName.match(rendererRegExp)) {
return renderer;
}
rendererEnum.moveNext();
}
return null;
}

// function FindRenderTemplate(renderer : Renderer, templateRegExp : RegExp) : RenderTemplate {
function FindRenderTemplate(renderer : Renderer, templateRegExp ) : RenderTemplate {
var templateEnum : Enumerator = new Enumerator(renderer.Templates);
while (!templateEnum.atEnd()) {
var renderTemplate : RenderTemplate = RenderTemplate(templateEnum.item());
if (renderTemplate.Name ==templateRegExp) {
return renderTemplate;
}
templateEnum.moveNext();
}
return null;
}

function SendError(message)
{
listBoxError.Items.Add(message); // put error into list
return;
}

}
}

try {
Application.Run(new VegasRenderMachinePkg.VegasRenderMachineCls());
} catch (E) {
throw (E);
}

// -----End File
SonyPJM wrote on 7/25/2003, 1:56 PM
Using a FileSystemWatcher is great!

In this case, Vegas does redraw (I only said it won't redraw in _some_
cases) but it is not usable... not even Vegas' menus work while
scripts run. Admittedly, this may be OK, preferable even, for your
app.

There is not a proper way to dock script GUIs right now. Considering
they'd be disposed of before the script completes, there's probably no
use for it at this point... scripts and their GUIs are modal for now.

If you start running into problems, I'd be suspicious of two things:

1) You're calling Application.Run with your form rather than just
calling its Show() method.

2) You're calling Vegas.Render on a separate thread... not
recommended.


If these things do turn out to be a problem, maybe you can create a
managed app that just sends WM_COPYDATA messages to Vegas when it is
time to render... sample code is available
here.