AddImageSequence class issue (PNG sequence import)

CyberOtter wrote on 10/11/2013, 2:59 AM
Hello,

I try to use « AddImageSequence() » to import several images sequences from several sub-directories to my vegas bin project.
I managed to tell the script to find every image sequence but i don’t know how to use « AddImageSequence() » class into my script.

Here is the script :

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;

public class EntryPoint
{
Vegas myVegas ; //= new Vegas();
String dirToScan = "E:\\Script_ImageSequence";
static System.Collections.Specialized.StringCollection log = new System.Collections.Specialized.StringCollection();

public void FromVegas(Vegas vegas)
{
System.IO.DirectoryInfo rootDir = new System.IO.DirectoryInfo(dirToScan);
WalkDirectoryTree(rootDir);
}

static void WalkDirectoryTree(System.IO.DirectoryInfo root)
{
System.IO.FileInfo[] files = null;
System.IO.DirectoryInfo[] subDirs = null;

try
{
files = root.GetFiles("*.*");
}
catch (UnauthorizedAccessException e)
{
log.Add(e.Message);
}
catch (System.IO.DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
}

if (files != null)
{
int num = 1;
String fileName = "";
foreach (System.IO.FileInfo fi in files)
{
if(num == 1)
{fileName = fi.FullName;}
num++;
}
num--;

if(num > 1 && !String.IsNullOrEmpty(fileName))
{
double fps = 25;
//MessageBox.Show("le premier fichier s\'appelle : "+fileName+" et il y a "+num+" fichiers dans le dossier "+root);
MediaPool.AddImageSequence(fileName,num,fps);
}

subDirs = root.GetDirectories();

foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
WalkDirectoryTree(dirInfo);
}

}
}
}


When i try to run it, vegas displays this error :

« Erreur 0x80131600 »
« …\import_image_sequence.cs(58) : Une référence d'objet est requise pour la propriété, la méthode ou le champ non statique 'Sony.Vegas.MediaPool.AddImageSequence(string, int, double)' »

Could someone help me ?
Thanks

Comments

Gary James wrote on 10/11/2013, 8:17 AM
In the entry point to your script, you don't appear to be saving the passed Vegas object reference. The only way you can reference the MediaPool is via the Vegas object.


public void FromVegas(Vegas vegas)
{
System.IO.DirectoryInfo rootDir = new System.IO.DirectoryInfo(dirToScan);
WalkDirectoryTree(rootDir);
}

This is missing the Vegas object reference.
MediaPool.AddImageSequence(fileName,num,fps);

It should be something like this:
vegas.Project.MediaPool.AddImageSequence(fileName,num,fps);

Where "vegas" is the Vegas object reference passed to the entry point function.

CyberOtter wrote on 10/11/2013, 9:13 AM
Thanks for the response.

Previous to your post i had modified the script to resolve the first error.... only to get a new one. :(

here is the new script :






[CODE]using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;

public class EntryPoint
{
static Vegas myVegas ;
String dirToScan = "E:\\Script_ImageSequence";
static System.Collections.Specialized.StringCollection log = new System.Collections.Specialized.StringCollection();

public void FromVegas(Vegas vegas)
{
System.IO.DirectoryInfo rootDir = new System.IO.DirectoryInfo(dirToScan);
try{
WalkDirectoryTree(rootDir);
}
catch (System.IO.DirectoryNotFoundException e)
{
MessageBox.Show(e.Message);
}
}

static void WalkDirectoryTree(System.IO.DirectoryInfo root)
{
System.IO.FileInfo[] files = null;
System.IO.DirectoryInfo[] subDirs = null;

try
{
files = root.GetFiles("*.*");
}
catch (UnauthorizedAccessException e)
{
log.Add(e.Message);
}
catch (System.IO.DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
}

if (files != null)
{
int num = 1;
String fileName = "";
foreach (System.IO.FileInfo fi in files)
{
if(num == 1)
{fileName = fi.FullName;}
num++;
}
num--;

if(num > 1 && !String.IsNullOrEmpty(fileName))
{
double fps = 25;
MessageBox.Show("le premier fichier s\'appelle : "+fileName+" et il y a "+num+" fichiers dans le dossier "+root);
myVegas.Project.MediaPool.AddImageSequence(fileName,num,fps);
}

subDirs = root.GetDirectories();

foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
WalkDirectoryTree(dirInfo);
}
}
}
}
[/CODE]

But now, right after the first dialog box (which means the script did compile well...)
...I got a new error message :

"System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
à EntryPoint.WalkDirectoryTree(DirectoryInfo root)
à EntryPoint.WalkDirectoryTree(DirectoryInfo root)
à EntryPoint.FromVegas(Vegas vegas)
--- Fin de la trace de la pile d'exception interne ---
à System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
à Sony.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName)
à Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)
"

Any ideas ?
Thanks
Gary James wrote on 10/11/2013, 9:20 AM
Are you compiling the script into a DLL? If so, why don't you simply run it in the Visual Studio debugger?
CyberOtter wrote on 10/11/2013, 9:23 AM
Actually, i dont really compile it into anything.

It is a .cs script which i run into Vegas directly.

Sorry for the misleading word.
jetdv wrote on 10/11/2013, 9:39 AM
Make the first line of this routine:

public void FromVegas(Vegas vegas)

to be:

myVegas = vegas;


At this point, "myVegas" in your script is undefined/null when you try to use it. You're defining the variable but you're never giving it a value.
CyberOtter wrote on 10/11/2013, 9:55 AM
Thanks to both of you.

The script is now working, and it will save me SO MUCH time (i got hundreds of png seqs to deal with :) )

Btw, gratz to your fantastic tools.
I use TimelineTools on daily basis, and some functions of Excalibur on occasion.

You're a bless to the Vegas Community.

Thanks Again.
John Romein wrote on 3/7/2015, 9:57 PM
Great script...exactly what I need...almost! I need the ability to add the images as 16, 18, or 24 fps and this script seems to only add as 25 fps. I played with the "double fps = 25" line and it did nothing to the fps.

Where is the fps set?

Can this script be modified to disable resample as the media is being loaded?
John Romein wrote on 3/8/2015, 6:57 PM
Ignore the last little note....re:disable resample.....realized that this can be done simply by updating one event and pasting attributes to the other events.