Script: Saving Media Pool fields to a file

roger_74 wrote on 1/30/2003, 5:37 AM
Here's the script Shaun asked for. It's a very simple script that doesn't have all the functionality he wanted, but maybe someone else can contribute. It has no real errorchecking at the moment, and something seems odd about TimecodeOut. It doesn't correspond to the TimecodeOut you see in the Media Pool, maybe what we see there is Length - TimecodeOut?

I chose HTML for the output, because that's the only easy way I could think of to get a nice table with variable width. If I'd done a textfile it would have had to be with a monotyped font with fixed fieldwidths.

Note that horizontal tabs have been replaced with nonbreaking spaces to keep the indenting in the code, otherwise it disappears when you post on this forum. This makes the HTML output a bit bigger than it has to be.

-----------------------

import System.Text;
import System.IO;
import System.Windows.Forms;
import SonicFoundry.Vegas.Script;

var mediaEnum = new Enumerator(Vegas.Project.MediaPool);

if (mediaEnum.atEnd())
{
    MessageBox.Show("There is no media in this project.");
}
else
{
    var output : StringBuilder = new StringBuilder();

    output.Append("<TABLE BORDER=\"1\" CELLPADDING=\"4\" CELLSPACING=\"0\">\n");
    output.Append("    <TR>\n");
    output.Append("        <TH>\n");
    output.Append("            Name\n");
    output.Append("        </TH>\n");
    output.Append("        <TH>\n");
    output.Append("            Comment\n");
    output.Append("        </TH>\n");
    output.Append("        <TH>\n");
    output.Append("            TimecodeIn\n");
    output.Append("        </TH>\n");
    output.Append("        <TH>\n");
    output.Append("            TimecodeOut\n");
    output.Append("        </TH>\n");
    output.Append("        <TH>\n");
    output.Append("            Length\n");
    output.Append("        </TH>\n");
    output.Append("    </TR>\n");

    while (!mediaEnum.atEnd())
    {
        output.Append("    <TR>\n");

        var media = mediaEnum.item();

        output.Append("        <TD>\n            " + media.FilePath + "\n        </TD>\n");
        output.Append("        <TD>\n            " + media.Comment + "\n        </TD>\n");
        output.Append("        <TD>\n            " + media.TimecodeIn + "\n        </TD>\n");
        output.Append("        <TD>\n            " + media.TimecodeOut + "\n        </TD>\n");
        output.Append("        <TD>\n            " + media.Length + "\n        </TD>\n");
        mediaEnum.moveNext();

        output.Append("    </TR>\n");
    }

    output.Append("</TABLE>\n");

    var filename : String = SaveAs()
    if (filename != "") WriteFile(filename, output.ToString());
}

function SaveAs()
{
    var saveFileDialog1 : SaveFileDialog = new SaveFileDialog();

    saveFileDialog1.DefaultExt = "html";
    saveFileDialog1.Filter = "HTML (*.html)|*.html";
    saveFileDialog1.Title = "Save Media Pool List as";

    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
        return saveFileDialog1.FileName;
    }
    else
    {
        return "";
    }
}

function WriteFile(fileName, content)
{
    var writer : StreamWriter = new StreamWriter(fileName);
    writer.WriteLine(content);
    writer.Close();
}

Comments

shaunn wrote on 1/30/2003, 11:45 AM
Thanks Roger 74 for giving it a try.

Few problems:

When I run the script I get two error:

"Error on line 59: 'return' statement outside of function"

"Error on line 1: Variable 'importSystem' has not been declared"

I am using VV4beta on Windows XP home oem.(if that helps)


Shaun

roger_74 wrote on 1/30/2003, 12:15 PM
If it says importSystem, something went wrong when you copied the code. It's supposed to be import System.

And regarding the return statement outside of function, did you accidentally remove a "}"?

I just tried the script by copying it straight from my post, and I had no problems.
taliesin wrote on 1/30/2003, 7:23 PM
I tested it too and it worked well.

Marco
shaunn wrote on 1/31/2003, 7:01 AM
Yeah something went wrong when I copied and paste. Sorry about that. It works fine now.

Thanks again Roger. I appreciate the help.

Shaun
Arnar wrote on 1/31/2003, 2:42 PM
What does this script do exactly?
roger_74 wrote on 1/31/2003, 4:22 PM
It makes a list (an HTML table) of all the media in the Media Pool. Only useful if you want a printed copy I guess. The columns are File, Comment, Timecode In/Out and Length. You can easily add/remove columns if you want.