Years ago I downloaded a modified batch render script, Batch Render V2.cs, that allowed you to name the individual rendered files.
I've been using this since V12 or 13, I'm not sure which. When I tried to use it today in V20 the menu was so small I couldn't use it so I dove in and doubled the size of each of the menu related variables & that did the trick
How can I share it here (the upload button won't accept it)?
Upload google drive or other online storage, then share link
Or, you can post the codes with instruction what format to save and where to place
You can just paste the text of the script and then select that text and use the <> button for that selected area.
Here is a google drive link:
https://drive.google.com/file/d/1Smi6VCiVFNXrxjGRJq674X-S1Z5g7eIy/view?usp=share_link
Here is the text, in case the drive folder is deleted someday:
I made the mods for Magix compatibility a few years ago and increased the size of the menu earlier this week.
/* Batch Render v2 by SkrowTox */
/* Update 0 */
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using ScriptPortal.Vegas;
using System.Security.Principal;
using Region = ScriptPortal.Vegas.Region;
public class EntryPoint
{
// set this to true if you want to allow files to be overwritten
private bool _overwriteExistingFile = false;
private String _defaultBasePath = "Untitled";
private Vegas _myVegas = null;
ArrayList _selectedTemplates = new ArrayList();
private static int _regionStartIndex = 1;
private bool _canceled = false;
static string IsAnAdministrator()
{
WindowsIdentity identity =
WindowsIdentity.GetCurrent();
if (identity != null)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator) ? "True" : "False";
}
return "Error";
}
enum RenderMode
{
Project = 0,
Selection,
Regions
}
class RenderItem
{
public readonly Renderer Renderer = null;
public readonly RenderTemplate Template = null;
public readonly String Extension = null;
public RenderItem(Renderer r, RenderTemplate t, String e)
{
Renderer = r;
Template = t;
// need to strip off the extension's leading "*"
if (null != e) Extension = e.TrimStart('*');
}
}
static String FixFileName(String name)
{
const Char replacementChar = '-';
foreach (char badChar in Path.GetInvalidFileNameChars())
{
name = name.Replace(badChar, replacementChar);
}
return name;
}
static void ValidateFilePath(String filePath)
{
if (filePath.Length > 260)
throw new ApplicationException("File name too long: " + filePath);
foreach (char badChar in Path.GetInvalidPathChars())
{
if (0 <= filePath.IndexOf(badChar))
{
throw new ApplicationException("Invalid file name: " + filePath);
}
}
}
bool ProjectHasVideo()
{
foreach (Track track in _myVegas.Project.Tracks)
{
if (track.IsVideo())
{
return true;
}
}
return false;
}
bool ProjectHasAudio()
{
foreach (Track track in _myVegas.Project.Tracks)
{
if (track.IsAudio())
{
return true;
}
}
return false;
}
static string GetValue(string attName)
{
return Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\SkrowTox\SonyVegasSettings", attName, "").ToString();
}
static void SetValue(string attName, string attValue)
{
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\SkrowTox\SonyVegasSettings", attName, attValue);
}
public void FromVegas(Vegas vegas)
{
_myVegas = vegas;
// Set default folder
String projectPath = vegas.Project.FilePath;
_defaultBasePath = String.IsNullOrEmpty(projectPath) ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) : Path.GetDirectoryName(projectPath);
// Show Dialog
DialogResult result = ShowBatchRenderDialog();
_myVegas.UpdateUI();
if (result == DialogResult.OK)
{
try{SetValue(@"DefaultDirectory", _defaultFolderTextBox.Text);}catch{}
try { SetValue(@"Naming", _namingTextBox.Text); }catch { }
// Inform the user of some special failure cases
String outputFilePath = Path.Combine(_defaultFolderTextBox.Text, GetFileNameFromNaming(_namingTextBox.Text, ""));
RenderMode renderMode = RenderMode.Project;
if (_renderRegionsRadioButton.Checked) renderMode = RenderMode.Regions;
else if (_renderSelectionRadioButton.Checked) renderMode = RenderMode.Selection;
// Do Rendering
DoBatchRender(_selectedTemplates, outputFilePath, renderMode);
}
if (result == DialogResult.OK && _shutdownCheckbox.Checked && !_canceled)
ShowShutDownDialog();
}
string GetFileNameFromNaming(int regionInt, string regionText, string tempName)
{
String tempString = _namingTextBox.Text;
tempString = tempString.Replace("[PFNAME]", String.IsNullOrEmpty(_myVegas.Project.FilePath) ? "Untitled" : Path.GetFileNameWithoutExtension(_myVegas.Project.FilePath));
tempString = tempString.Replace("[RINT]", regionInt.ToString());
tempString = tempString.Replace("[RTITLE]", regionText);
tempString = tempString.Replace("[TNAME]", tempName);
tempString = tempString.Replace("[RINT+1]", (regionInt + 1).ToString());
return FixFileName(tempString);
}
string GetFileNameFromNaming(string text, string templName)
{
text = text.Replace("[PFNAME]", String.IsNullOrEmpty(_myVegas.Project.FilePath) ? "Untitled" : Path.GetFileNameWithoutExtension(_myVegas.Project.FilePath));
text = text.Replace("[PFNAME]", Path.GetFileNameWithoutExtension(_myVegas.Project.FilePath));
text = text.Replace("[RINT]", "");
text = text.Replace("[RTITLE]", "");
text = text.Replace("[TNAME]", templName);
text = text.Replace("[RINT+1]", "");
return FixFileName(text);
}
static void Button2Click(object sender, EventArgs e)
{
MessageBox.Show("Varialbes to use in naming:\n" +
"[PFNAME]: Project File Name (if not saved results in Untitled)\n\n" +
"[RINT]: Current region index (is vital when using Render Regions without region titles)\n\n" +
"[RINT+1]: Starts calculating region index from 1\n\n" +
"[RTITLE]: Current region title (results in error if region titles are the same while not using [RINT])\n\n" +
"[TNAME]: Template name (is vital if selected more than one template from the same codec)\n\n");
}
void DoBatchRender(ArrayList selectedTemplates, String basePath, RenderMode renderMode)
{
String outputDirectory = Path.GetDirectoryName(basePath);
// make sure templates are selected
if ((null == selectedTemplates) || (0 == selectedTemplates.Count))
throw new ApplicationException("No render templates selected.");
// make sure the output directory exists
if (!Directory.Exists(outputDirectory))
throw new ApplicationException("The output directory does not exist.");
RenderStatus status = RenderStatus.Canceled;
// Enumerate through each selected render template
foreach (RenderItem renderItem in selectedTemplates)
{
if (renderMode == RenderMode.Regions)
{
for (int index = _regionStartIndex -1; index < _myVegas.Project.Regions.Count; index++)
{
Region region = _myVegas.Project.Regions[index];
String regionFilename = GetFileNameFromNaming(_regionStartIndex -1, region.Label, renderItem.Template.Name) +
renderItem.Extension;
// Render the region
status = DoRender(regionFilename, renderItem, region.Position, region.Length);
if (status == RenderStatus.Canceled)
{
_canceled = true;
break;
}
_regionStartIndex++;
}
}
else
{
String filename = GetFileNameFromNaming(_namingTextBox.Text, renderItem.Template.Name) + renderItem.Extension;
Timecode renderStart, renderLength;
if (renderMode == RenderMode.Selection)
{
renderStart = _myVegas.SelectionStart;
renderLength = _myVegas.SelectionLength;
}
else
{
renderStart = new Timecode();
renderLength = _myVegas.Project.Length;
}
status = DoRender(filename, renderItem, renderStart, renderLength);
}
if (status == RenderStatus.Canceled)
{
_canceled = true;
break;
}
}
}
RenderStatus DoRender(String filePath, RenderItem renderItem, Timecode start, Timecode length)
{
filePath = Path.Combine(_defaultFolderTextBox.Text, filePath);
ValidateFilePath(filePath);
// Make sure the file does not already exist
if (!_overwriteExistingFile && File.Exists(filePath)) throw new ApplicationException("File already exists: " + filePath);
// Perform the render
RenderStatus status = _myVegas.Render(filePath, renderItem.Template, start, length);
switch (status)
{
case RenderStatus.Complete:
case RenderStatus.Canceled:
break;
default:
StringBuilder msg = new StringBuilder("Render failed:\n");
msg.Append("\n file name: ");
msg.Append(filePath);
msg.Append("\n Renderer: ");
msg.Append(renderItem.Renderer.FileTypeName);
msg.Append("\n Template: ");
msg.Append(renderItem.Template.Name);
msg.Append("\n Start Time: ");
msg.Append(start.ToString());
msg.Append("\n Length: ");
msg.Append(length.ToString());
throw new ApplicationException(msg.ToString());
}
return status;
}
private TextBox _defaultFolderTextBox;
private TextBox _namingTextBox;
private TreeView _templatesTreeView;
private RadioButton _renderProjectRadioButton;
private RadioButton _renderSelectionRadioButton;
private RadioButton _renderRegionsRadioButton;
private CheckBox _shutdownCheckbox;
private Form _dlog;
DialogResult ShowBatchRenderDialog()
{
// Main Form
_dlog = new Form();
_dlog.Text = @"Batch Render v2A";
_dlog.FormBorderStyle = FormBorderStyle.FixedDialog;
_dlog.MaximizeBox = false;
_dlog.StartPosition = FormStartPosition.CenterScreen;
_dlog.Width = 1200;
_dlog.Height = 886;
// Default Folder Label
Label label1 = new Label();
label1.AutoSize = true;
label1.Location = new Point(24, 18);
label1.Size = new Size(152, 26);
label1.Text = @"Default Folder:";
// Default Folder TextBox
_defaultFolderTextBox = new TextBox();
_defaultFolderTextBox.Location = new Point(188, 12);
_defaultFolderTextBox.Size = new Size(794, 40);
_defaultFolderTextBox.Text = _defaultBasePath;
// Browse Button
Button button1 = new Button();
button1.Location = new Point(994, 8);
button1.Size = new Size(150, 46);
button1.Text = @"Browse...";
// Naming Label
Label label2 = new Label();
label2.AutoSize = true;
label2.Location = new Point(84, 70);
label2.Size = new Size(92, 26);
label2.Text = @"Naming:";
// Naming TextBox
_namingTextBox = new TextBox();
_namingTextBox.Location = new Point(188, 64);
_namingTextBox.Size = new Size(794, 40);
_namingTextBox.Text = @"[PFNAME]";
// Templates TreeView
_templatesTreeView = new TreeView();
_templatesTreeView.Location = new Point(30, 116);
_templatesTreeView.Size = new Size(1114, 600);
_templatesTreeView.CheckBoxes = true;
// Render Project RadioButton
_renderProjectRadioButton = new RadioButton();
_renderProjectRadioButton.AutoSize = true;
_renderProjectRadioButton.Checked = true;
_renderProjectRadioButton.Location = new Point(30, 728);
_renderProjectRadioButton.Size = new Size(192, 34);
_renderProjectRadioButton.Text = @"Render Project";
// Render Selection RadioButton
_renderSelectionRadioButton = new RadioButton();
_renderSelectionRadioButton.AutoSize = true;
_renderSelectionRadioButton.Location = new Point(234, 728);
_renderSelectionRadioButton.Size = new Size(214, 34);
_renderSelectionRadioButton.Text = @"Render Selection";
if (0 == _myVegas.SelectionLength.Nanos) _renderSelectionRadioButton.Enabled = false;
// Render Regions RadioButton
_renderRegionsRadioButton = new RadioButton();
_renderRegionsRadioButton.AutoSize = true;
_renderRegionsRadioButton.Location = new Point(460, 728);
_renderRegionsRadioButton.Size = new Size(2042, 34);
_renderRegionsRadioButton.Text = @"Render Regions";
if (_myVegas.Project.Regions.Count == 0) _renderRegionsRadioButton.Enabled = false;
_renderRegionsRadioButton.CheckedChanged += RenderRegionsRadioButtonCheckedChanged;
// Shutdown CheckBox
_shutdownCheckbox = new CheckBox();
_shutdownCheckbox.AutoSize = true;
_shutdownCheckbox.Location = new Point(30, 774);
_shutdownCheckbox.Size = new Size(442, 34);
_shutdownCheckbox.Text = @"Shutdown PC when rendering completes.";
// Button Variables
Button button2 = new Button();
button2.Location = new Point(994, 58);
button2.Size = new Size(150, 46);
button2.Text = @"Variables";
button2.Click += Button2Click;
// Button OK
Button okButton = new Button();
okButton.Location = new Point(832, 740);
okButton.Size = new Size(150, 43);
okButton.Text = @"OK";
okButton.DialogResult = DialogResult.OK;
// Button Cancel
Button cancelButton = new Button();
cancelButton.Location = new Point(994, 740);
cancelButton.Size = new Size(150, 46);
cancelButton.Text = @"Cancel";
cancelButton.DialogResult = DialogResult.Cancel;
// Set Actions
button1.Click += HandleBrowseClick;
_dlog.FormClosing += HandleFormClosing;
_templatesTreeView.AfterCheck += HandleTreeViewCheck;
// Options Button
Button optButton = new Button();
optButton.Location = new Point(670, 740);
optButton.Size = new Size(150, 46);
optButton.Text = @"Options";
optButton.Click += OptButtonClick;
// Test Button
Button testButton = new Button();
testButton.Location = new Point(30, 58);
testButton.Size = new Size(42, 46);
testButton.Text = @"T";
testButton.Click += TestButtonClick;
// Add Controls
_dlog.Controls.Add(label1);
_dlog.Controls.Add(label2);
_dlog.Controls.Add(_namingTextBox);
_dlog.Controls.Add(_renderProjectRadioButton);
_dlog.Controls.Add(_renderRegionsRadioButton);
_dlog.Controls.Add(_renderSelectionRadioButton);
_dlog.Controls.Add(_shutdownCheckbox);
_dlog.Controls.Add(_templatesTreeView);
_dlog.Controls.Add(button1);
_dlog.Controls.Add(cancelButton);
_dlog.Controls.Add(okButton);
_dlog.Controls.Add(_defaultFolderTextBox);
_dlog.Controls.Add(button2);
_dlog.Controls.Add(optButton);
_dlog.Controls.Add(testButton);
FillTemplateTree();
// Try to read
try{if (GetValue(@"DefaultDirectory") != "") _defaultFolderTextBox.Text = GetValue(@"DefaultDirectory");}catch{}
try { if (GetValue(@"Naming") != "") _namingTextBox.Text = GetValue(@"Naming"); }catch { }
if (IsAnAdministrator() == "False")
{
_shutdownCheckbox.Enabled = false;
_shutdownCheckbox.Text += @" (No Admin Rights)";
}
// Show Dialog
return _dlog.ShowDialog(_myVegas.MainWindow);
}
void TestButtonClick(object sender, EventArgs e)
{
UpdateSelectedTemplates();
if (_renderRegionsRadioButton.Checked)
{
if (_selectedTemplates.Count > 0)
MessageBox.Show(GetFileNameFromNaming(0, _myVegas.Project.Regions[0].Label, ((RenderItem)_selectedTemplates[0]).Template.Name) + ((RenderItem)_selectedTemplates[0]).Extension);
else MessageBox.Show(GetFileNameFromNaming(0, _myVegas.Project.Regions[0].Label, "[Template Name]") + @".ext");
}
else
{
if (_selectedTemplates.Count > 0)
MessageBox.Show(GetFileNameFromNaming(_namingTextBox.Text, ((RenderItem)_selectedTemplates[0]).Template.Name) + ((RenderItem)_selectedTemplates[0]).Extension);
else
MessageBox.Show(GetFileNameFromNaming(_namingTextBox.Text, "[Template Name]") + @".ext");
}
_selectedTemplates.Clear();
}
private CheckBox _checkBox1;
void OptButtonClick(object sender, EventArgs e)
{
// Main Form
Form form = new Form();
form.Text = @"Options";
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.MaximizeBox = false;
form.StartPosition = FormStartPosition.CenterScreen;
form.Width = 359;
form.Height = 121;
// Start Render Label
Label label1 = new Label();
label1.AutoSize = true;
label1.Location = new Point(12, 9);
label1.Size = new Size(107, 13);
label1.Text = @"Region Render Start:";
// Domain up Down
DomainUpDown domainUpDown1 = new DomainUpDown();
domainUpDown1.Location = new Point(125, 7);
domainUpDown1.Size = new Size(206, 20);
domainUpDown1.Text = @"1";
domainUpDown1.ReadOnly = true;
// Button OK
Button okButton = new Button();
okButton.Location = new Point(175, 56);
okButton.Size = new Size(75, 23);
okButton.Text = @"OK";
okButton.DialogResult = DialogResult.OK;
// Button Cancel
Button cancelButton = new Button();
cancelButton.Location = new Point(256, 54);
cancelButton.Size = new Size(75, 23);
cancelButton.Text = @"Cancel";
cancelButton.DialogResult = DialogResult.Cancel;
// Auto Overwrite
_checkBox1 = new CheckBox();
_checkBox1.AutoSize = true;
_checkBox1.Location = new Point(15, 33);
_checkBox1.Size = new Size(160, 17);
_checkBox1.Text = @"Automatically Overwrite Files";
_checkBox1.CheckedChanged += CheckBox1CheckedChanged;
form.Controls.Add(label1);
form.Controls.Add(domainUpDown1);
form.Controls.Add(okButton);
form.Controls.Add(cancelButton);
form.Controls.Add(_checkBox1);
_checkBox1.Checked = _overwriteExistingFile;
if (_myVegas.Project.Regions.Count > 0)
{
for (int i = 0; i < _myVegas.Project.Regions.Count; i++)
domainUpDown1.Items.Add((i + 1).ToString());
domainUpDown1.Text = _regionStartIndex == 0 ? @"1" : _regionStartIndex.ToString();
}
else domainUpDown1.Enabled = false;
if (form.ShowDialog(_dlog) == DialogResult.OK)
{
if (domainUpDown1.Enabled) _regionStartIndex = Convert.ToInt32(domainUpDown1.Text);
}
}
void CheckBox1CheckedChanged(object sender, EventArgs e)
{
_overwriteExistingFile = _checkBox1.Checked;
}
void RenderRegionsRadioButtonCheckedChanged(object sender, EventArgs e)
{
if (_renderRegionsRadioButton.Checked && _renderRegionsRadioButton.Enabled)
_namingTextBox.Text += @"[RINT]";
else
_namingTextBox.Text = _namingTextBox.Text.Replace("[RINT]", "");
}
void FillTemplateTree()
{
int projectAudioChannelCount = 0;
if (AudioBusMode.Stereo == _myVegas.Project.Audio.MasterBusMode)
{
projectAudioChannelCount = 2;
}
else if (AudioBusMode.Surround == _myVegas.Project.Audio.MasterBusMode)
{
projectAudioChannelCount = 6;
}
bool projectHasVideo = ProjectHasVideo();
bool projectHasAudio = ProjectHasAudio();
foreach (Renderer renderer in _myVegas.Renderers)
{
try
{
String rendererName = renderer.FileTypeName;
TreeNode rendererNode = new TreeNode(rendererName);
rendererNode.Tag = new RenderItem(renderer, null, null);
foreach (RenderTemplate template in renderer.Templates)
{
try
{
// filter out invalid templates
if (!template.IsValid())
{
continue;
}
// filter out video templates when project has
// no video.
if (!projectHasVideo && (0 < template.VideoStreamCount))
{
continue;
}
// filter out audio-only templates when project has no audio
if (!projectHasAudio && (0 == template.VideoStreamCount) && (0 < template.AudioStreamCount))
{
continue;
}
// filter out templates that have more channels than the project
if (projectAudioChannelCount < template.AudioChannelCount)
{
continue;
}
// filter out templates that don't have
// exactly one file extension
String[] extensions = template.FileExtensions;
if (1 != extensions.Length)
{
continue;
}
String templateName = template.Name;
TreeNode templateNode = new TreeNode(templateName);
templateNode.Tag = new RenderItem(renderer, template, extensions[0]);
rendererNode.Nodes.Add(templateNode);
}
catch (Exception e)
{
// skip it
MessageBox.Show(e.ToString());
}
}
if (0 == rendererNode.Nodes.Count)
{
continue;
}
if (1 == rendererNode.Nodes.Count)
{
// skip it if the only template is the project
// settings template.
if (0 == ((RenderItem)rendererNode.Nodes[0].Tag).Template.Index)
{
continue;
}
}
else
{
_templatesTreeView.Nodes.Add(rendererNode);
}
}
catch
{
// skip it
}
}
}
void UpdateSelectedTemplates()
{
_selectedTemplates.Clear();
foreach (TreeNode node in _templatesTreeView.Nodes)
{
foreach (TreeNode templateNode in node.Nodes)
{
if (templateNode.Checked)
{
_selectedTemplates.Add(templateNode.Tag);
}
}
}
}
void HandleBrowseClick(Object sender, EventArgs args)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowNewFolderButton = true;
if (null != _defaultFolderTextBox)
{
String initialDir = _defaultFolderTextBox.Text;
if (Directory.Exists(initialDir))
{
folderBrowserDialog.SelectedPath = initialDir;
}
}
if (DialogResult.OK != folderBrowserDialog.ShowDialog()) return;
if (null != _defaultFolderTextBox)
{
_defaultFolderTextBox.Text = folderBrowserDialog.SelectedPath;
}
}
static void HandleTreeViewCheck(object sender, TreeViewEventArgs args)
{
if (args.Node.Checked)
{
if (0 != args.Node.Nodes.Count)
{
if ((args.Action == TreeViewAction.ByKeyboard) || (args.Action == TreeViewAction.ByMouse))
{
SetChildrenChecked(args.Node, true);
}
}
else if (!args.Node.Parent.Checked)
{
args.Node.Parent.Checked = true;
}
}
else
{
if (0 != args.Node.Nodes.Count)
{
if ((args.Action == TreeViewAction.ByKeyboard) || (args.Action == TreeViewAction.ByMouse))
{
SetChildrenChecked(args.Node, false);
}
}
else if (args.Node.Parent.Checked)
{
if (!AnyChildrenChecked(args.Node.Parent))
{
args.Node.Parent.Checked = false;
}
}
}
}
void HandleFormClosing(Object sender, FormClosingEventArgs args)
{
Form dlg = sender as Form;
if (null == dlg) return;
if (DialogResult.OK != dlg.DialogResult) return;
String outputFilePath = Path.Combine(_defaultFolderTextBox.Text, GetFileNameFromNaming(_namingTextBox.Text, ""));
try
{
String outputDirectory = Path.GetDirectoryName(outputFilePath);
if (!Directory.Exists(outputDirectory)) throw new ApplicationException();
}
catch
{
String title = "Invalid Directory";
StringBuilder msg = new StringBuilder();
msg.Append("The output directory does not exist.\n");
msg.Append("Please specify the directory and base file name using the Browse button.");
MessageBox.Show(dlg, msg.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
args.Cancel = true;
return;
}
try
{
String baseFileName = Path.GetFileName(outputFilePath);
if (String.IsNullOrEmpty(baseFileName)) throw new ApplicationException();
if (-1 != baseFileName.IndexOfAny(Path.GetInvalidFileNameChars())) throw new ApplicationException();
}
catch
{
String title = "Invalid Base File Name";
StringBuilder msg = new StringBuilder();
msg.Append("The base file name is not a valid file name.\n");
msg.Append("Make sure it contains one or more valid file name characters.");
MessageBox.Show(dlg, msg.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
args.Cancel = true;
return;
}
UpdateSelectedTemplates();
if (0 == _selectedTemplates.Count)
{
String title = "No Templates Selected";
StringBuilder msg = new StringBuilder();
msg.Append("No render templates selected.\n");
msg.Append("Select one or more render templates from the available formats.");
MessageBox.Show(dlg, msg.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
args.Cancel = true;
return;
}
}
static void SetChildrenChecked(TreeNode node, bool checkIt)
{
foreach (TreeNode childNode in node.Nodes)
{
if (childNode.Checked != checkIt)
childNode.Checked = checkIt;
}
}
static bool AnyChildrenChecked(TreeNode node)
{
foreach (TreeNode childNode in node.Nodes)
{
if (childNode.Checked) return true;
}
return false;
}
Button _button1;
readonly Timer _tim = new Timer();
int _iTime = 0;
Form _dlog1;
void ShowShutDownDialog()
{
_dlog1 = new Form();
_dlog1.FormBorderStyle = FormBorderStyle.None;
_dlog1.MaximizeBox = false;
_dlog1.StartPosition = FormStartPosition.CenterScreen;
_dlog1.Width = 600;
_dlog1.TopMost = true;
_dlog1.Size = new Size(137, 60);
Label textLabel = new Label();
textLabel.AutoSize = true;
textLabel.Location = new Point(12, 9);
textLabel.Size = new Size(118, 13);
textLabel.TabIndex = 0;
textLabel.Text = @"Shutdown in progress...";
_dlog1.Controls.Add(textLabel);
_button1 = new Button();
_button1.Location = new Point(30, 35);
_button1.Size = new Size(75, 23);
_button1.TabIndex = 1;
_button1.Text = @"Cancel";
_button1.UseVisualStyleBackColor = true;
_button1.Click += Button1Click;
_button1.DialogResult = DialogResult.Cancel;
_dlog1.Controls.Add(_button1);
_tim.Interval = 1000;
_iTime = 0;
_tim.Tick += TimTick;
_tim.Enabled = true;
_tim.Start();
_dlog1.ShowDialog(_myVegas.MainWindow);
return;
}
void Button1Click(object sender, EventArgs e)
{
_tim.Stop();
_tim.Enabled = false;
}
void TimTick(object sender, EventArgs e)
{
if (_iTime == 10)
{
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PreShutdownSave.veg"))
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PreShutdownSave.veg");
_myVegas.SaveProject(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PreShutdownSave.veg");
_myVegas.Exit();
Process.Start("Shutdown", "-s -t 10");
_dlog1.Close();
_tim.Enabled = false; // DO NOT REMOVE
_tim.Stop(); // DO NOT REMOVE
}
else _iTime++;
}
}
The better place is:
[My Documents]\Vegas Script Menu
Then it will show up in all versions of VEGAS and you don't have to modify they VEGAS Program folder.
@3d87c4 Thank you for this. It will be useful.
The better place is:
[My Documents]\Vegas Script Menu
Then it will show up in all versions of VEGAS and you don't have to modify they VEGAS Program folder.
@jetdv Thank you. I never knew that, and the application Help has always said to put custom scripts in C:\Program Files\VEGAS\VEGAS Pro XX.0\Script Menu\. This is much better.
An excellent script I use for rendering, made by @jetdv, is this one:
using System;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Data;
//using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using ScriptPortal.Vegas;
namespace JETDV_Render_Script
{
public partial class Form1 : Form
{
public Vegas myVegas;
private Renderer[] FullRenderer = new Renderer[999];
private RenderTemplate[] FullTemplate = new RenderTemplate[999];
private bool GotFileNames = false;
private string[] fileNames;
public Form1(Vegas vegas)
{
myVegas = vegas;
InitializeComponent();
FindAllRenderers();
if (!myVegas.Project.IsUntitled)
{
txtFileName.Text = Path.GetFileNameWithoutExtension(myVegas.Project.FilePath);
}
}
public void FindAllRenderers()
{
int RCount = 0;
try
{
foreach (Renderer renderer in myVegas.Renderers)
{
try
{
foreach (RenderTemplate renderTemplate in renderer.Templates)
{
if (renderTemplate.IsValid())
{
FullRenderer[RCount] = renderer;
FullTemplate[RCount] = renderTemplate;
cmbRenderType.Items.Add(renderer.Name + " - " + renderTemplate.Name);
RCount++;
}
}
}
catch
{
}
}
}
catch
{
}
if (cmbRenderType.SelectedIndex < 0)
{
cmbRenderType.SelectedIndex = 0;
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
txtDirBox.Text = GetSaveDir(txtDirBox.Text);
}
private void btnRender_Click(object sender, EventArgs e)
{
Renderer myRenderer = FullRenderer[cmbRenderType.SelectedIndex];
RenderTemplate myTemplate = FullTemplate[cmbRenderType.SelectedIndex];
if (rdoFull.Checked)
{
string FullFileName = txtDirBox.Text + txtFileName.Text + myRenderer.FileExtension.Substring(1, 4);
Timecode RStart = new Timecode("00:00:00:00");
Timecode RLength = myVegas.Project.Length;
DoRender(FullFileName, myRenderer, myTemplate, RStart, RLength, false, false);
}
if (rdoRegion.Checked)
{
foreach(Region myRegion in myVegas.Project.Regions)
{
string FullFileName = txtDirBox.Text + "Region " + myRegion.Index + " " + txtFileName.Text + myRenderer.FileExtension.Substring(1, 4);
if (chkRegionLabels.Checked)
{
FullFileName = txtDirBox.Text + myRegion.Label + myRenderer.FileExtension.Substring(1, 4);
}
Timecode RStart = myRegion.Position;
Timecode RLength = myRegion.Length;
DoRender(FullFileName, myRenderer, myTemplate, RStart, RLength, false, false);
}
}
if (rdoSpecial.Checked)
{
DoSpecialRender(myRenderer, myTemplate);
}
if (rdoProjects.Checked)
{
renderProjects(myRenderer, myTemplate);
}
if (rdoSnapshot.Checked)
{
exportImage();
}
}
private void exportImage()
{
// save original project and preview settings
VideoRenderQuality origPreviewRenderQuality = myVegas.Project.Preview.RenderQuality;
bool origPreviewFillSize = myVegas.Project.Preview.FullSize;
VideoFieldOrder origFieldOrder = myVegas.Project.Video.FieldOrder;
VideoDeinterlaceMethod origProjectDeinterlaceMethod = myVegas.Project.Video.DeinterlaceMethod;
// Set the preview quality and size.
myVegas.Project.Preview.RenderQuality = VideoRenderQuality.Best;
myVegas.Project.Preview.FullSize = true;
// Set the field order and deinterlace method
myVegas.Project.Video.FieldOrder = VideoFieldOrder.ProgressiveScan;
myVegas.Project.Video.DeinterlaceMethod = VideoDeinterlaceMethod.InterpolateFields;
myVegas.UpdateUI();
string FullFileName = txtDirBox.Text + txtFileName.Text + ".png";
myVegas.SaveSnapshot(FullFileName, ImageFileFormat.PNG, myVegas.Transport.CursorPosition);
// restore the project and preview settings
myVegas.Project.Preview.RenderQuality = origPreviewRenderQuality;
myVegas.Project.Preview.FullSize = origPreviewFillSize;
myVegas.Project.Video.FieldOrder = origFieldOrder;
myVegas.Project.Video.DeinterlaceMethod = origProjectDeinterlaceMethod;
}
private void renderProjects(Renderer myRenderer, RenderTemplate myTemplate)
{
if (!GotFileNames)
{
MessageBox.Show("You must get the files to render before you can choose this option. Please press the 'Select Projects' button.");
return;
}
// Read the files
foreach (String file in fileNames)
{
myVegas.NewProject(false, false);
myVegas.OpenProject(file);
if (chkProjReg.Checked)
{
foreach (Region myRegion in myVegas.Project.Regions)
{
string FullFileName = txtDirBox.Text + "Region " + myRegion.Index + " " + txtFileName.Text + myRenderer.FileExtension.Substring(1, 4);
if (chkRegionLabels.Checked)
{
FullFileName = txtDirBox.Text + myRegion.Label + myRenderer.FileExtension.Substring(1, 4);
}
Timecode RStart = myRegion.Position;
Timecode RLength = myRegion.Length;
DoRender(FullFileName, myRenderer, myTemplate, RStart, RLength, false, false);
}
}
else
{
string FullFileName = txtDirBox.Text + Path.GetFileNameWithoutExtension(file) + txtFileName.Text + myRenderer.FileExtension.Substring(1, 4);
Timecode RStart = new Timecode("00:00:00:00");
Timecode RLength = myVegas.Project.Length;
DoRender(FullFileName, myRenderer, myTemplate, RStart, RLength, false, false);
}
}
myVegas.NewProject(false, false);
}
public void DoSpecialRender(Renderer myRenderer, RenderTemplate myTemplate)
{
// Mute all tracks
foreach (Track myTrack in myVegas.Project.Tracks)
{
myTrack.Mute = true;
}
// Do all of the renders
foreach (Track myTrack in myVegas.Project.Tracks)
{
myTrack.Mute = false;
int TrackNum = myTrack.Index + 1;
foreach (Region myRegion in myVegas.Project.Regions)
{
int RegionNum = myRegion.Index + 1;
string FullFileName = txtDirBox.Text;
if (myRegion.Label == "")
{
FullFileName = FullFileName + "Region " + RegionNum;
}
else
{
FullFileName = FullFileName + myRegion.Label;
}
FullFileName = FullFileName + " Track" + TrackNum + " " + txtFileName.Text + myRenderer.FileExtension.Substring(1, 4);
Timecode RStart = myRegion.Position;
Timecode RLength = myRegion.Length;
DoRender(FullFileName, myRenderer, myTemplate, RStart, RLength, false, false);
}
myTrack.Mute = true;
}
// UnMute all tracks
foreach (Track myTrack in myVegas.Project.Tracks)
{
myTrack.Mute = false;
}
}
public string GetSaveDir(string OrgSaveDir)
{
if (OrgSaveDir == null)
{
OrgSaveDir = "";
}
FolderBrowserDialog saveFileDialog = new FolderBrowserDialog();
saveFileDialog.Description = "Select the desired folder";
saveFileDialog.ShowNewFolderButton = true;
if (!(OrgSaveDir == ""))
{
string initialDir = OrgSaveDir;
if (Directory.Exists(initialDir))
{
saveFileDialog.SelectedPath = initialDir;
}
}
else
{
saveFileDialog.SelectedPath = "c:\\";
}
if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog())
{
return Path.GetFullPath(saveFileDialog.SelectedPath) + Path.DirectorySeparatorChar;
}
else
{
return OrgSaveDir;
}
}
public void DoRender(string fileName, Renderer rndr, RenderTemplate rndrTemplate, Timecode start, Timecode length, bool IncMarkers, bool SetStretch)
{
// make sure the file does not already exist
bool overwriteExistingFiles = true;
if (!overwriteExistingFiles && File.Exists(fileName))
{
MessageBox.Show("File already exists: " + fileName);
return;
}
//MessageBox.Show(fileName);
if (File.Exists(fileName))
{
try
{
File.Delete(fileName);
}
catch
{
}
}
if (File.Exists(fileName))
{
try
{
myVegas.Project.MediaPool.Remove(fileName);
myVegas.UpdateUI();
File.Delete(fileName);
}
catch
{
}
}
if (File.Exists(fileName))
{
MessageBox.Show("Could not delete: " + fileName);
return;
}
// perform the render. The Render method returns
// a member of the RenderStatus enumeration. If
// it is anything other than OK, exit the loops.
RenderArgs args = new RenderArgs();
args.OutputFile = fileName;
args.RenderTemplate = rndrTemplate;
args.Start = start;
args.Length = length;
args.IncludeMarkers = IncMarkers;
args.StretchToFill = SetStretch;
RenderStatus status = myVegas.Render(args);
//RenderStatus status = Vegas.Render(fileName, rndrTemplate, start, length);
// if the render completed successfully, just return
if (status == RenderStatus.Complete)
return;
// if the user canceled, throw out a special message that won't be
// displayed.
if (status == RenderStatus.Canceled)
{
MessageBox.Show("User canceled");
return;
}
// if the render failed, throw out a detailed error message.
StringBuilder msg = new StringBuilder("Render failed:\n");
msg.Append("\n file name: ");
msg.Append(fileName);
msg.Append("\n Renderer: ");
msg.Append(rndr.FileTypeName);
msg.Append("\n Template: ");
msg.Append(rndrTemplate.Name);
msg.Append("\n Start Time: ");
msg.Append(start.ToString());
msg.Append("\n Length: ");
msg.Append(length.ToString());
MessageBox.Show(Convert.ToString(msg));
}
private void btnProjects_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "VEGAS Projects (*.VEG)|*.VEG|All files (*.*)|*.*";
ofd.Multiselect = true;
ofd.Title = "Select the VEGAS Projects to render";
DialogResult dr = ofd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
fileNames = ofd.FileNames;
GotFileNames = true;
}
else
{
GotFileNames = false;
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmbRenderType = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtDirBox = new System.Windows.Forms.TextBox();
this.txtFileName = new System.Windows.Forms.TextBox();
this.btnBrowse = new System.Windows.Forms.Button();
this.btnRender = new System.Windows.Forms.Button();
this.rdoFull = new System.Windows.Forms.RadioButton();
this.rdoRegion = new System.Windows.Forms.RadioButton();
this.rdoSpecial = new System.Windows.Forms.RadioButton();
this.rdoProjects = new System.Windows.Forms.RadioButton();
this.btnProjects = new System.Windows.Forms.Button();
this.rdoSnapshot = new System.Windows.Forms.RadioButton();
this.chkRegionLabels = new System.Windows.Forms.CheckBox();
this.chkProjReg = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// cmbRenderType
//
this.cmbRenderType.FormattingEnabled = true;
this.cmbRenderType.Location = new System.Drawing.Point(118, 44);
this.cmbRenderType.Margin = new System.Windows.Forms.Padding(2);
this.cmbRenderType.Name = "cmbRenderType";
this.cmbRenderType.Size = new System.Drawing.Size(360, 21);
this.cmbRenderType.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 46);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Select Renderer";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 80);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(77, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Save Directory";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(11, 113);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 13);
this.label3.TabIndex = 3;
this.label3.Text = "File Name";
//
// txtDirBox
//
this.txtDirBox.Location = new System.Drawing.Point(118, 80);
this.txtDirBox.Margin = new System.Windows.Forms.Padding(2);
this.txtDirBox.Name = "txtDirBox";
this.txtDirBox.Size = new System.Drawing.Size(273, 20);
this.txtDirBox.TabIndex = 4;
//
// txtFileName
//
this.txtFileName.Location = new System.Drawing.Point(118, 113);
this.txtFileName.Margin = new System.Windows.Forms.Padding(2);
this.txtFileName.Name = "txtFileName";
this.txtFileName.Size = new System.Drawing.Size(216, 20);
this.txtFileName.TabIndex = 5;
//
// btnBrowse
//
this.btnBrowse.Location = new System.Drawing.Point(421, 78);
this.btnBrowse.Margin = new System.Windows.Forms.Padding(2);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Size = new System.Drawing.Size(56, 19);
this.btnBrowse.TabIndex = 6;
this.btnBrowse.Text = "Browse";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
//
// btnRender
//
this.btnRender.Location = new System.Drawing.Point(118, 260);
this.btnRender.Margin = new System.Windows.Forms.Padding(2);
this.btnRender.Name = "btnRender";
this.btnRender.Size = new System.Drawing.Size(56, 19);
this.btnRender.TabIndex = 7;
this.btnRender.Text = "Render";
this.btnRender.UseVisualStyleBackColor = true;
this.btnRender.Click += new System.EventHandler(this.btnRender_Click);
//
// rdoFull
//
this.rdoFull.AutoSize = true;
this.rdoFull.Checked = true;
this.rdoFull.Location = new System.Drawing.Point(118, 145);
this.rdoFull.Margin = new System.Windows.Forms.Padding(2);
this.rdoFull.Name = "rdoFull";
this.rdoFull.Size = new System.Drawing.Size(79, 17);
this.rdoFull.TabIndex = 8;
this.rdoFull.TabStop = true;
this.rdoFull.Text = "Full Render";
this.rdoFull.UseVisualStyleBackColor = true;
//
// rdoRegion
//
this.rdoRegion.AutoSize = true;
this.rdoRegion.Location = new System.Drawing.Point(118, 168);
this.rdoRegion.Margin = new System.Windows.Forms.Padding(2);
this.rdoRegion.Name = "rdoRegion";
this.rdoRegion.Size = new System.Drawing.Size(59, 17);
this.rdoRegion.TabIndex = 9;
this.rdoRegion.Text = "Region";
this.rdoRegion.UseVisualStyleBackColor = true;
//
// rdoSpecial
//
this.rdoSpecial.AutoSize = true;
this.rdoSpecial.Location = new System.Drawing.Point(118, 191);
this.rdoSpecial.Margin = new System.Windows.Forms.Padding(2);
this.rdoSpecial.Name = "rdoSpecial";
this.rdoSpecial.Size = new System.Drawing.Size(98, 17);
this.rdoSpecial.TabIndex = 10;
this.rdoSpecial.TabStop = true;
this.rdoSpecial.Text = "Special Render";
this.rdoSpecial.UseVisualStyleBackColor = true;
//
// rdoProjects
//
this.rdoProjects.AutoSize = true;
this.rdoProjects.Location = new System.Drawing.Point(118, 214);
this.rdoProjects.Margin = new System.Windows.Forms.Padding(2);
this.rdoProjects.Name = "rdoProjects";
this.rdoProjects.Size = new System.Drawing.Size(63, 17);
this.rdoProjects.TabIndex = 11;
this.rdoProjects.TabStop = true;
this.rdoProjects.Text = "Projects";
this.rdoProjects.UseVisualStyleBackColor = true;
//
// btnProjects
//
this.btnProjects.Location = new System.Drawing.Point(185, 213);
this.btnProjects.Margin = new System.Windows.Forms.Padding(2);
this.btnProjects.Name = "btnProjects";
this.btnProjects.Size = new System.Drawing.Size(116, 19);
this.btnProjects.TabIndex = 12;
this.btnProjects.Text = "Select Projects";
this.btnProjects.UseVisualStyleBackColor = true;
this.btnProjects.Click += new System.EventHandler(this.btnProjects_Click);
//
// rdoSnapshot
//
this.rdoSnapshot.AutoSize = true;
this.rdoSnapshot.Location = new System.Drawing.Point(118, 236);
this.rdoSnapshot.Margin = new System.Windows.Forms.Padding(2);
this.rdoSnapshot.Name = "rdoSnapshot";
this.rdoSnapshot.Size = new System.Drawing.Size(70, 17);
this.rdoSnapshot.TabIndex = 13;
this.rdoSnapshot.TabStop = true;
this.rdoSnapshot.Text = "Snapshot";
this.rdoSnapshot.UseVisualStyleBackColor = true;
//
// chkRegionLabels
//
this.chkRegionLabels.AutoSize = true;
this.chkRegionLabels.Checked = true;
this.chkRegionLabels.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkRegionLabels.Location = new System.Drawing.Point(231, 168);
this.chkRegionLabels.Name = "chkRegionLabels";
this.chkRegionLabels.Size = new System.Drawing.Size(116, 17);
this.chkRegionLabels.TabIndex = 14;
this.chkRegionLabels.Text = "Use Region Labels";
this.chkRegionLabels.UseVisualStyleBackColor = true;
//
// chkProjReg
//
this.chkProjReg.AutoSize = true;
this.chkProjReg.Location = new System.Drawing.Point(306, 215);
this.chkProjReg.Name = "chkProjReg";
this.chkProjReg.Size = new System.Drawing.Size(189, 17);
this.chkProjReg.TabIndex = 15;
this.chkProjReg.Text = "Render Regions Instead of Project";
this.chkProjReg.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(530, 297);
this.Controls.Add(this.chkProjReg);
this.Controls.Add(this.chkRegionLabels);
this.Controls.Add(this.rdoSnapshot);
this.Controls.Add(this.btnProjects);
this.Controls.Add(this.rdoProjects);
this.Controls.Add(this.rdoSpecial);
this.Controls.Add(this.rdoRegion);
this.Controls.Add(this.rdoFull);
this.Controls.Add(this.btnRender);
this.Controls.Add(this.btnBrowse);
this.Controls.Add(this.txtFileName);
this.Controls.Add(this.txtDirBox);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmbRenderType);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "Form1";
this.Text = "JETDV Render Script";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox cmbRenderType;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtDirBox;
private System.Windows.Forms.TextBox txtFileName;
private System.Windows.Forms.Button btnBrowse;
private System.Windows.Forms.Button btnRender;
private System.Windows.Forms.RadioButton rdoFull;
private System.Windows.Forms.RadioButton rdoRegion;
private System.Windows.Forms.RadioButton rdoSpecial;
private System.Windows.Forms.RadioButton rdoProjects;
private System.Windows.Forms.Button btnProjects;
private System.Windows.Forms.RadioButton rdoSnapshot;
private System.Windows.Forms.CheckBox chkRegionLabels;
private System.Windows.Forms.CheckBox chkProjReg;
}
}
public class EntryPoint
{
private static JETDV_Render_Script.Form1 form;
public void FromVegas(Vegas vegas)
{
form = new JETDV_Render_Script.Form1(vegas);
form.ShowDialog();
}
}
I find it very complete, and really very useful.
In addition to the suggestion of putting it on a cloud drive, I also suggest you link it in your Vegas signature. I've done that with my own variation of the stock Batch Render making it easy for me to snatch and install to new machines. Also makes it easy to share with others saying, "You can download it from my signature." I put my own in a zip along with an icon so I can dump both of them together into the [My Documents]\Vegas Script Menu folder ... another trick learned from @jetdv.
LOL...computer finally died & I just came here to download the script for my new one.