basic (?) script help

daves2 wrote on 8/1/2004, 10:46 PM
I am trying to create a script to add markers to a project based on timecodes which exist in a text file (each line of the text file is hh:mm:ss.ff0, ff0=frame).

Looked for an existing script to read the text file and create markers, but couldn't find one. I've never created a script, but thought I'd modify an existing one & give it a try.

I found the following (w/ deference to who ever created it - it's not labelled). Any suggestions for how I'd modify it to read from a text file and loop through the file creating markers for each entry in the file?

TIA for any help....

/**
* This script will add markers at the specified interval
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;

//Change this value to be the desired interval
//Format: hh:mm:ss:ff (hours:minutes:seconds:frames)
var Interval = "00:05:00:00";


try {
var myMarker : Marker;
var IncTime : Timecode = new Timecode(Interval);
var CurrTime : Timecode = IncTime;
var EndTime : Timecode = Vegas.Project.Length;

while (CurrTime < EndTime) {
//Put a marker at the interval point
myMarker = new Marker(CurrTime);
Vegas.Project.Markers.Add(myMarker);
CurrTime = CurrTime + IncTime;
}



} catch (e) {
MessageBox.Show(e);
}

Comments

JohnnyRoy wrote on 8/2/2004, 8:32 PM
Instead pf just giving you the code to open and read a file, I though I would just write a script will do what you want and you could use that to expand on.
/** 
* Program: MarkersFromFile.js
* Description: This script will read timecodes from a text file with one timecode
* on each line in the format hh:ss:ss.ff and create a marker
*
* Author: Johnny (Roy) Rofrano john_rofrano (at) hotmail (dot) com
*
* Date: Aug 2, 2004
*
**/
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;
var file : StreamReader = null; 
try
{
var scriptPath : String = Path.GetDirectoryName(this.ScriptFile);
var filename : String = scriptPath + Path.DirectorySeparatorChar + "markers.txt";
file = File.OpenText(filename);
var input : String = null;
while ((input = file.ReadLine()) != null)
{
var marker : Marker = new Marker(new Timecode(input));
Vegas.Project.Markers.Add(marker);
}
}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// make sure you don't leave the file open
if (file != null)
{
file.Close();
}
}
/*** END OF SCRIPT ***/
~jr