Error with script calling render templates

Rosebud wrote on 3/30/2012, 5:36 AM
This script works fine on most configurations running VP11 (add a video and audio track before to run it):


using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Sony.Vegas;

public class EntryPoint
{
Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;
bool flag = false;
foreach (Renderer render in myVegas.Renderers)
{
render.Templates.Refresh();
foreach (RenderTemplate renderTamplate in render.Templates)
{
if (renderTamplate.IsValid())
continue;

MessageBox.Show(render.Name);
flag = true;
}
}
if (!flag)
MessageBox.Show("No invalid template found");
}
}


However, on some configuration, the script return this error:



Any thoughts about this behavior ?
Many thx for your help.

Gilles

Comments

Gary James wrote on 3/30/2012, 9:15 AM
After Vegas version 7 I've found that Vegas was changed to force users into supporting the built-in UNDO capability. This meant wrapping each piece of code that made any changes to the project configuration in an Undo block. The text in the Undo block is what appears in the Undo drop-down on the Vegas toolbar.

using ( new UndoBlock ( "Undo whatever is in the following code" ) )
{
// lines of code that modify the project configuration
}


It's possible that Vegas is interpreting your render.Templates.Refresh(); statement as an alteration of something inside Vegas. This is an easy change you can make to see if this is the problem.
Rosebud wrote on 3/30/2012, 12:04 PM
Thx Gary but the error still occur without the "render.Templates.Refresh()" statement.
Undo blocks aren't designed for custom command only ?
jetdv wrote on 3/31/2012, 7:27 AM
Yes, undo blocks are only for custom commands. I've seen issues reading templates as well so I simply added extra error catching - something like this:


try
{
foreach (Renderer renderer in myVegas.Renderers)
{
try
{
foreach (RenderTemplate renderTemplate in renderer.Templates)
{
if (renderTemplate.IsValid())
{
// use renderer & renderTemplate as desired
MessageBox.Show(renderer.Name + " - " + renderTemplate.Name);
}
}
}
catch
{
}
}
}
catch
{
}
Rosebud wrote on 4/4/2012, 12:01 PM
Many thx for your help Edward.
I’m waiting answer from users of my script "ProxyStream" to know if problem is solved.
Do you know a way to determine which codec/template can cause this error ?
The ā€œ.IsValid()" function is useless in this case.

Thx again
Gilles
jetdv wrote on 4/4/2012, 3:42 PM
I've never tried to specifically figure out where the error occurs. I'm just catching the error and ignoring it and moving on to the next renderer.