Custom command cannot create New Project

dbritta1 wrote on 2/3/2009, 10:40 AM
The following custom command always throws an exception.

using System;
using System.Collections;
using System.Windows.Forms;
using Sony.Vegas;

public class SampleModule : ICustomCommandModule
{
protected Vegas myVegas = null;

public void InitializeModule(Vegas vegas)
{
myVegas = vegas;
}

public ICollection GetCustomCommands()
{
CustomCommand cmd = new CustomCommand(CommandCategory.Tools, "NewProjectBug");
cmd.DisplayName = "NewProjectBug";
cmd.Invoked += this.HandleInvoked;
return new CustomCommand[] { cmd };
}

void HandleInvoked(Object sender, EventArgs args)
{
using (UndoBlock undo = new UndoBlock("NewProjectBug"))
{
try
{
// This generates an exception
Project project = new Project();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}


Any ideas what could be going on?

Comments

dbritta1 wrote on 2/3/2009, 11:23 AM
Solution is to move new project creation outside of undo block.
Dennis
jetdv wrote on 2/3/2009, 11:29 AM
"NewProject" is not undoable. Therefore it needs to be done OUTSIDE the "undo" block. This will work:


void HandleInvoked(Object sender, EventArgs args)
{
Project project = new Project();
using (UndoBlock undo = new UndoBlock("NewProjectBug"))
{
try
{
// Whatever you do IN the new project.
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}