Scripting

herb wrote on 9/2/2003, 3:07 PM
As anyone notice that some of the scrips that ran in V4c will not run in V4d the one in question is Snapshot I used it often in V4c I try to use it in V4d and it will not work I keep getting a error that veriable not set on line 42. I looked at line 42 and it is set at best. Not knowing anything about scripting I don't know what to do next need help.

Thanks

Comments

jetdv wrote on 9/2/2003, 3:17 PM
I know of no changes that would cause a script working in 4.0c to not work in 4.0d (even though you can have a script that works in 4.0d but not in 4.0c). How about posting that script somewhere where we may be able to diagnose what is wrong.

I tested the "SnapshotToFile.js" script here and it worked fine.
herb wrote on 9/2/2003, 3:29 PM
Ok jetdv here the script hope this helps

// This script makes a snapshot from the timeline and adds it to mediapool

import System.Windows.Forms;
import SonicFoundry.Vegas.Script;
import SonicFoundry.Vegas;
import System.IO;
import Microsoft.Win32;

// The first thing this script does is save off the preview & project
// settings that will be set later. This is so they can be restored
// after the script is complete.
var origPreviewRenderQuality = Vegas.Project.Preview.RenderQuality;
var origPreviewFillSize = Vegas.Project.Preview.FullSize;
var origFieldOrder = Vegas.Project.Video.FieldOrder;
var origProjectDeinterlaceMethod = Vegas.Project.Video.DeinterlaceMethod;
var currentTime = Vegas.Cursor;


try {
// Last snapshot file name is stored in Windows registry.
var regKey = Registry.CurrentUser.CreateSubKey("Software\\Sonic Foundry\\Scripts");

var imageFileName = regKey.GetValue("Snapshot");
if (imageFileName == null) { // Running for the first time.
// The current project path seems to fit.
imageFileName = Path.GetDirectoryName(Vegas.Project.FilePath);
imageFileName += Path.DirectorySeparatorChar;
imageFileName += "Image001.png";
} else {
// Increment number.
var filename = Path.GetFileNameWithoutExtension(imageFileName);
var i = filename.Length - 1;
while ((i >= 0) && System.Char.IsDigit(filename, i))
i--;
i++;
var j = filename.Length - i;
var imageNdex: int = parseInt(filename.Substring(i, j), 10) + 1;
var nextname = String.Format("{0}{1:d" + j + "}", filename.Substring(0, i), imageNdex);
imageFileName = imageFileName.Replace(filename, nextname);
}

// Set the preview quality and size.
Vegas.Project.Preview.RenderQuality = VideoRenderQuality.Best;
Vegas.Project.Preview.FullSize = true;

// Set the field order and deinterlace method
Vegas.Project.Video.FieldOrder = VideoFieldOrder.ProgressiveScan;
Vegas.Project.Video.DeinterlaceMethod = VideoDeinterlaceMethod.InterpolateFields;

// Show the script's dialog box.
var dialog = new SaveFileDialog();
dialog.Filter = "PNG File (*.png)|*.png|JPEG File (*.jpg)|*.jpg";
dialog.CheckPathExists = true;
dialog.AddExtension = true;
var initialDir = Path.GetDirectoryName(imageFileName);
if (Directory.Exists(initialDir)) {
dialog.InitialDirectory = initialDir;
}
dialog.DefaultExt = Path.GetExtension(imageFileName);
dialog.FileName = Path.GetFileNameWithoutExtension(imageFileName);

// if the OK button was pressed...
if (dialog.ShowDialog() == DialogResult.OK) {
// Get the basis for output image file names
imageFileName = Path.GetFullPath(dialog.FileName);

// Get the output image file name extension and corresponding
// file format. ImageFileFormat.None indicates that the
// current prefs setting will be used but that may not
// correspond to the specified file extension.
var imageFileNameExt = Path.GetExtension(imageFileName);
var imageFormat = ImageFileFormat.PNG;
if (0 == String.Compare(imageFileNameExt, ".jpg", true)) {
imageFormat = ImageFileFormat.JPEG;
}

// save a snapshot. The SaveSnapshot method returns a
// member of the RenderStatus enumeration. If the user
// hits the escape key or quits the app, exit the loop.
if (Vegas.SaveSnapshot(imageFileName, imageFormat, currentTime) == RenderStatus.Complete) {
regKey.SetValue("Snapshot", imageFileName);
Clipboard.SetDataObject(System.Drawing.Image.FromFile(imageFileName), true);

// This is just ridiculous, all you have to do to add media to Media Pool is create a Media object!
var media = new Media(imageFileName);
Vegas.UpdateUI();
}
}
} catch (e) {
MessageBox.Show(e);
}

// restore the project and preview settings
Vegas.Project.Preview.RenderQuality = origPreviewRenderQuality;
Vegas.Project.Preview.FullSize = origPreviewFillSize;
Vegas.Project.Video.FieldOrder = origFieldOrder;
Vegas.Project.Video.DeinterlaceMethod = origProjectDeinterlaceMethod;
Vegas.Cursor = currentTime;
jetdv wrote on 9/2/2003, 3:35 PM
The script, as posted, ran just fine on 4.0d here. You may need to reinstall the .NET framework and/or Vegas.
herb wrote on 9/2/2003, 3:48 PM
Thanks jetdv I will give it another try after I reload .NET framework and if that does not work I will reload Vegas thanks so much for your help I will let you know later of the out come.

Thanks
johnmeyer wrote on 9/2/2003, 5:11 PM
A few of the scripts I have download recently said they needed the latest .NET download.
herb wrote on 9/3/2003, 5:23 PM
To jetdv

Well I reloaded V4d and .NET 1.1 still same error message "Veriable not set on line 42" I give up thanks anyway for all your help.
jetdv wrote on 9/3/2003, 9:28 PM
The next step is to reinstall Vegas.