What is wrong in this code. showing long file name. invalid error

iEmby wrote on 8/11/2024, 1:36 PM
using ScriptPortal.Vegas;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Quick_Render_by_iEmby
{
    public partial class Form3 : Form
    {
        private Vegas vegas;
        private ArrayList SelectedTemplates = new ArrayList();
        private List<RenderItem> renderItems = new List<RenderItem>();

        enum RenderMode
        {
            Project = 0,
            Selection,
            Regions,
        }

        public Form3(Vegas vegas)
        {
            InitializeComponent();
            this.vegas = vegas;
            AttachEventHandlers();

            treeView1.CheckBoxes = true;
            FillTemplateTree();
        }

        private void AttachEventHandlers()
        {
            button1.Click += new EventHandler(RenderSelection_Click);
            button2.Click += new EventHandler(RenderRegions_Click);
            button3.Click += new EventHandler(RenderProject_Click);
            button5.Click += new EventHandler(Cancel_Click);
        }

        private void RenderSelection_Click(object sender, EventArgs e)
        {
            foreach (TreeNode rendererNode in treeView1.Nodes)
            {
                foreach (TreeNode templateNode in rendererNode.Nodes)
                {
                    if (templateNode.Checked)
                    {
                        RenderItem renderItem = (RenderItem)templateNode.Tag;
                        SelectedTemplates.Add(renderItem);
                    }
                }
            }

            if (SelectedTemplates.Count == 0)
            {
                MessageBox.Show("No render templates selected.");
                return;
            }

            // Proceed with batch rendering
            Render(RenderMode.Selection);
        }

        private void RenderRegions_Click(object sender, EventArgs e)
        {
            foreach (TreeNode rendererNode in treeView1.Nodes)
            {
                foreach (TreeNode templateNode in rendererNode.Nodes)
                {
                    if (templateNode.Checked)
                    {
                        RenderItem renderItem = (RenderItem)templateNode.Tag;
                        SelectedTemplates.Add(renderItem);
                    }
                }
            }

            if (SelectedTemplates.Count == 0)
            {
                MessageBox.Show("No render templates selected.");
                return;
            }

            // Proceed with batch rendering
            InitializeBatchRendering(RenderMode.Regions);
        }

        private void RenderProject_Click(object sender, EventArgs e)
        {
            SelectedTemplates.Clear(); // Clear previous selections

            foreach (TreeNode rendererNode in treeView1.Nodes)
            {
                foreach (TreeNode templateNode in rendererNode.Nodes)
                {
                    if (templateNode.Checked)
                    {
                        RenderItem renderItem = (RenderItem)templateNode.Tag;
                        SelectedTemplates.Add(renderItem);
                    }
                }
            }

            if (SelectedTemplates.Count == 0)
            {
                MessageBox.Show("No render templates selected.");
                return;
            }

            // Proceed with batch rendering
            InitializeBatchRendering(RenderMode.Project);
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            // Close the form or cancel the rendering process
            this.Close();
        }

        private void Render(RenderMode renderMode)
        {
            // Prepare rendering based on the mode
            InitializeBatchRendering(renderMode);
        }

        private void InitializeBatchRendering(RenderMode renderMode)
        {
            // Check if the project is saved
            if (string.IsNullOrEmpty(vegas.Project.FilePath))
            {
                // Prompt user to save the project if not saved
                DialogResult result = MessageBox.Show(
                    "The project has not been saved. Do you want to save it now?",
                    "Save Project",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question
                );

                if (result == DialogResult.Yes)
                {
                    // Show SaveFileDialog
                    SaveFileDialog saveFileDialog = new SaveFileDialog
                    {
                        Filter = "Vegas Project Files (*.veg)|*.veg",
                        Title = "Save Project As"
                    };

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        vegas.Project.SaveProject(saveFileDialog.FileName);
                    }
                    else
                    {
                        // User chose not to save the project, cancel rendering
                        MessageBox.Show("Project must be saved before rendering.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    // User chose not to save the project, cancel rendering
                    MessageBox.Show("Project must be saved before rendering.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Check if SelectedTemplates is valid
            if (SelectedTemplates == null || SelectedTemplates.Count == 0)
            {
                MessageBox.Show("No templates selected for rendering.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Initialize batch rendering with the generated output file path
            DoBatchRender(SelectedTemplates, renderMode);
        }


        private void DoBatchRender(ArrayList selectedTemplates, RenderMode renderMode)
        {
            List<RenderArgs> renders = new List<RenderArgs>();
            string projectName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);

            foreach (RenderItem renderItem in selectedTemplates)
            {
                try
                {
                    string projectFilePath = vegas.Project.FilePath;
                    string projectDirectory = Path.GetDirectoryName(projectFilePath);
                    string renderDirectory = Path.Combine(projectDirectory, "Renders");
                    Directory.CreateDirectory(renderDirectory);

                    string outputFileName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);
                    string outputFilePath = Path.Combine(renderDirectory, outputFileName);


                    if (renderMode == RenderMode.Regions)
                    {
                        AddRegionRenders(renderItem, outputFilePath, renders);
                    }
                    else
                    {
                        AddSingleRender(renderItem, outputFilePath, renderMode, renders);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Error processing render item: {e.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            foreach (RenderArgs args in renders)
            {
                try
                {
                    if (DoRender(args) == RenderStatus.Canceled)
                        break;
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Rendering failed: {e.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }









        private void AddRegionRenders(RenderItem renderItem, string filename, List<RenderArgs> renders)
        {
            int regionIndex = 0;
            foreach (ScriptPortal.Vegas.Region region in vegas.Project.Regions)
            {
                string regionFilename = $"{filename}[{regionIndex}]{renderItem.Extension}";
                string projectFilePath = vegas.Project.FilePath;
                string projectDirectory = Path.GetDirectoryName(projectFilePath);
                string renderDirectory = Path.Combine(projectDirectory, "Renders");
                Directory.CreateDirectory(renderDirectory);

                string outputFileName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);
                string outputFilePath = Path.Combine(renderDirectory, outputFileName);

                RenderArgs args = new RenderArgs
                {
                    OutputFile = outputFilePath + regionFilename, // Fixed the syntax issue here
                    RenderTemplate = renderItem.Template,
                    Start = region.Position,
                    Length = region.Length,
                };
                renders.Add(args);
                regionIndex++;
            }
        }


        private void AddSingleRender(RenderItem renderItem, string filename, RenderMode renderMode, List<RenderArgs> renders)
        {

            filename += renderItem.Extension;
            string projectFilePath = vegas.Project.FilePath;
            string projectDirectory = Path.GetDirectoryName(projectFilePath);
            string renderDirectory = Path.Combine(projectDirectory, "Renders");
            Directory.CreateDirectory(renderDirectory);

            string outputFileName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);
            string outputFilePath = Path.Combine(renderDirectory, outputFileName);


            RenderArgs args = new RenderArgs
            {
                OutputFile = outputFilePath + filename, // Set 'overwrite' flag as needed
                RenderTemplate = renderItem.Template,
                UseSelection = (renderMode == RenderMode.Selection)
            };
            renders.Add(args);
        }


        private RenderStatus DoRender(RenderArgs args)
        {
            RenderStatus status = vegas.Render(args);
            if (status == RenderStatus.Failed)
            {
                StringBuilder msg = new StringBuilder("Render failed:\n");
                msg.Append("\n    file name: ").Append(args.OutputFile);
                msg.Append("\n    Template: ").Append(args.RenderTemplate.Name);
                throw new ApplicationException(msg.ToString());
            }
            return status;
        }


        static Guid[] TheDefaultTemplateRenderClasses =
        {
            Renderer.CLSID_SfWaveRenderClass,
            Renderer.CLSID_SfW64ReaderClass,
            Renderer.CLSID_CSfAIFRenderFileClass,
            Renderer.CLSID_CSfFLACRenderFileClass,
            Renderer.CLSID_CSfPCARenderFileClass,
        };

        bool AllowDefaultTemplates(Guid rendererID)
        {
            foreach (Guid guid in TheDefaultTemplateRenderClasses)
            {
                if (guid == rendererID)
                    return true;
            }
            return false;
        }

        private void FillTemplateTree()
        {
            int projectAudioChannelCount = (vegas.Project.Audio.MasterBusMode == AudioBusMode.Stereo) ? 2 : 6;
            bool projectHasVideo = ProjectHasVideo();
            bool projectHasAudio = ProjectHasAudio();
            int projectVideoStreams = (!projectHasVideo || vegas.Project.Video.Stereo3DMode != Stereo3DOutputMode.Off) ? 2 : 1;

            foreach (Renderer renderer in vegas.Renderers)
            {
                try
                {
                    string rendererName = renderer.FileTypeName;
                    TreeNode rendererNode = new TreeNode(rendererName)
                    {
                        Tag = new RenderItem(renderer, null, null)
                    };

                    foreach (RenderTemplate template in renderer.Templates)
                    {
                        try
                        {
                            if (!template.IsValid() ||
                                (!projectHasVideo && template.VideoStreamCount > 0) ||
                                (projectHasVideo && projectVideoStreams < template.VideoStreamCount) ||
                                (template.TemplateID == 0 && !AllowDefaultTemplates(renderer.ClassID)) ||
                                (!projectHasAudio && template.AudioStreamCount > 0 && template.VideoStreamCount == 0) ||
                                (projectAudioChannelCount < template.AudioChannelCount) ||
                                template.FileExtensions.Length != 1)
                            {
                                continue;
                            }

                            string templateName = template.Name;
                            TreeNode templateNode = new TreeNode(templateName)
                            {
                                Tag = new RenderItem(renderer, template, template.FileExtensions[0])
                            };
                            rendererNode.Nodes.Add(templateNode);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.ToString(), "Error");
                        }
                    }
                    treeView1.Nodes.Add(rendererNode);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "Error");
                }
            }
        }


        private bool ProjectHasVideo()
        {
            foreach (Track track in vegas.Project.Tracks)
            {
                if (track.IsVideo())
                    return true;
            }
            return false;
        }

        private bool ProjectHasAudio()
        {
            foreach (Track track in vegas.Project.Tracks)
            {
                if (track.IsAudio())
                    return true;
            }
            return false;
        }

        public class RenderItem
        {
            public Renderer Renderer { get; set; }
            public RenderTemplate Template { get; set; }
            public string Extension { get; set; }

            public RenderItem(Renderer renderer, RenderTemplate template, string extension)
            {
                Renderer = renderer;
                Template = template;
                Extension = extension;
            }
        }

    }
}

I know we have already a batch render script but i need this for my another script

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

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

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

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

INTERNAL GRAPHIC CARD (iGPU)

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

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

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

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

Comments

Robert Johnston wrote on 8/11/2024, 8:15 PM

@iEmby, There appears to be some code missing. You call IntializeComponent, but there isn't an InitializeComponent() routine. Variables for buttons 1,2,3,4,5 haven't been assigned. The variable treeview1 hasn't been assigned. That is, the objects for those variables haven't been created yet with New statements.

I can't tell you where those variables are supposed to be assigned, but until those are fixed, there's no need to go any further. Perhaps JetDV knows.

Intel Core i7 10700K CPU @ 3.80GHz (to 4.65GHz), NVIDIA GeForce RTX 2060 SUPER 8GBytes. Memory 32 GBytes DDR4. Also Intel UHD Graphics 630. Mainboard: Dell Inc. PCI-Express 3.0 (8.0 GT/s) Comet Lake. Bench CPU Multi Thread: 5500.5 per CPU-Z.

Vegas Pro 21.0 (Build 108) with Mocha Vegas

Windows 11 not pro

ChrisD wrote on 8/11/2024, 8:33 PM

Is the error being caught by your try/catch, or is it a fatal stop?

Absent of debugging interactvely, why not troubleshoot it and inspect your variables with a messagebox after each assignment?

iEmby wrote on 8/12/2024, 2:41 AM

@iEmby, There appears to be some code missing. You call IntializeComponent, but there isn't an InitializeComponent() routine. Variables for buttons 1,2,3,4,5 haven't been assigned. The variable treeview1 hasn't been assigned. That is, the objects for those variables haven't been created yet with New statements.

I can't tell you where those variables are supposed to be assigned, but until those are fixed, there's no need to go any further. Perhaps JetDV knows.

sir this is Form3.cs only but Form3.Designer is all perfect..all variables are assigned.

 

namespace Quick_Render_by_iEmby
{
    partial class Form3
    {
        /// <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.treeView1 = new System.Windows.Forms.TreeView();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.SuspendLayout();
            // 
            // treeView1
            // 
            this.treeView1.Location = new System.Drawing.Point(12, 10);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new System.Drawing.Size(585, 419);
            this.treeView1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button1.Location = new System.Drawing.Point(611, 10);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(176, 51);
            this.button1.TabIndex = 1;
            this.button1.Text = "Render SELECTION";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // button2
            // 
            this.button2.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button2.Location = new System.Drawing.Point(611, 64);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(176, 51);
            this.button2.TabIndex = 1;
            this.button2.Text = "Render REGIONS";
            this.button2.UseVisualStyleBackColor = true;
            // 
            // button3
            // 
            this.button3.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button3.Location = new System.Drawing.Point(611, 118);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(176, 51);
            this.button3.TabIndex = 1;
            this.button3.Text = "Render PROJECT";
            this.button3.UseVisualStyleBackColor = true;
            // 
            // button5
            // 
            this.button5.BackColor = System.Drawing.Color.DarkGray;
            this.button5.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button5.Location = new System.Drawing.Point(611, 378);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(176, 51);
            this.button5.TabIndex = 1;
            this.button5.Text = "Cancel";
            this.button5.UseVisualStyleBackColor = false;
            // 
            // progressBar1
            // 
            this.progressBar1.Location = new System.Drawing.Point(12, 435);
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.Size = new System.Drawing.Size(775, 23);
            this.progressBar1.TabIndex = 2;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 461);
            this.Controls.Add(this.progressBar1);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.treeView1);
            this.Name = "Form3";
            this.Text = "Form3";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.TreeView treeView1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.ProgressBar progressBar1;
    }
}

 

Last changed by iEmby on 8/12/2024, 2:45 AM, changed a total of 1 times.

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

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

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

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

INTERNAL GRAPHIC CARD (iGPU)

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

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

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

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

jetdv wrote on 8/12/2024, 8:36 AM

Where in the code is the error happening? (I'm sure it can be narrowed down to a specific subroutine)

And what, exactly, is the error that's happening?

iEmby wrote on 8/12/2024, 2:49 PM

when i render it shows output file name with *
but i checked many times in every way there is not single *
showing error

outputfilename*.mp4

file name invalid

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

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

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

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

INTERNAL GRAPHIC CARD (iGPU)

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

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

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

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

jetdv wrote on 8/12/2024, 8:05 PM

@iEmby on the full render? Or the region renders? It appears the full render information is here?

            string projectName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);

            foreach (RenderItem renderItem in selectedTemplates)
            {
                try
                {
                    string projectFilePath = vegas.Project.FilePath;
                    string projectDirectory = Path.GetDirectoryName(projectFilePath);
                    string renderDirectory = Path.Combine(projectDirectory, "Renders");
                    Directory.CreateDirectory(renderDirectory);

                    string outputFileName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);
                    string outputFilePath = Path.Combine(renderDirectory, outputFileName);

It looks like this is defined but never used???

string projectName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);

Then in the loop, change the above to this to see where the error may be appearing:

            foreach (RenderItem renderItem in selectedTemplates)
            {
                try
                {
                    string projectFilePath = vegas.Project.FilePath;
                    MessageBox.Show("Project File Path = " + projectFilePath);
                    string projectDirectory = Path.GetDirectoryName(projectFilePath);
                    MessageBox.Show("Project Directory = " + projectDirectory);
                    string renderDirectory = Path.Combine(projectDirectory, "Renders");
                    MessageBox.Show("Render Directory = " + renderDirectory);
                    Directory.CreateDirectory(renderDirectory);

                    string outputFileName = Path.GetFileNameWithoutExtension(vegas.Project.FilePath);
                    MessageBox.Show("Output File Name = " + outputFileName);
                    string outputFilePath = Path.Combine(renderDirectory, outputFileName);
                    MessageBox.Show("Output File Path = " + outputFilePath);

Do all of the variables look correct?

Also, for Directory.CreateDirectory(renderDirectory); I would check to see if the directory exists before creating it (over and over again)