Comments

Rosebud wrote on 9/19/2007, 12:50 PM
Short answers :
-Use Usercontrol instead of Form.
-Or use ContainerControl and change it to a Form for editing/design (Thx to jetdv for the trick).
DarrenStarr wrote on 9/28/2007, 9:35 AM
I have already written quite extensively based on this feature. In fact, the second the trial version went public, I started porting over a huge amount of code to do just this.

1) First, create a Visual Studio Project for C#, select Windows/Class Library
2) Right click your project, then select "Add Reference"
3) Select the Browse, locate the Sony.Vegas.dll in the Sony Vegas program installation directory.
4) Add references for the .NET assemblies for System.Windows.Forms and whatever else you'll need.
5) Right click the project and open up the project properties
6) Click the Debug tab
7) Choose "Start External Program" and find vegas80.exe
8) For command line arguments, make sure you provide a -CMDMODULE:"c:\where my application is built for debug\the dll file.dll" option
9) Delete the Class1.cs file from the project, it's not needed
10) Create a new class, I recommend "VegasEntryPoint.cs" as the filename
11) pop some code in, similar to the following
using System;
using System.Collections;
using Sony.Vegas;

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

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

CustomCommand invokeTransportStreamToolsCommand = new CustomCommand(CommandCategory.Tools, "Transport Stream Tools");

public ICollection GetCustomCommands()
{
invokeTransportStreamToolsCommand.MenuPopup += this.handleTransportStreamToolsMenuPopup;
invokeTransportStreamToolsCommand.Invoked += this.handleTransportStreamToolsCommandInvoked;
return new CustomCommand[] { invokeTransportStreamToolsCommand };
}

void handleTransportStreamToolsMenuPopup(Object sender, EventArgs args)
{
CustomCommand cmd = (CustomCommand)sender;
cmd.Checked = myVegas.FindDockView("TransportStreamTools");
}

void handleTransportStreamToolsCommandInvoked(Object sender, EventArgs args)
{
if (!myVegas.ActivateDockView("TransportStreamTools"))
{
Vegas8TransportTools.TransportStreamTools dockView = new Vegas8TransportTools.TransportStreamTools();
dockView.AutoLoadCommand = invokeTransportStreamToolsCommand;
myVegas.LoadDockView(dockView);
}
}
}

notice that class does not exist within a namespace, it's within the global namespace.

I'm not 100% sure, but I believe that the class name is irrelevant, it appears vegas enumerates all the ICustomCommandModule instances.

The initialize module function member is the first one called.

The function GetCustomCommands is called to return the commands that should be added to the menus. You can choose from a few different menus. My implementation returns a reference to invokeTransportStreamToolsCommand which is displayed on the tools menu.

The handleTransportStreamToolsMenuPopup function is called by vegas when the menu is displayed to find out if the menu item should be altered, in the example I've provided, it checks to see if the tool pane I've created is active or not. It knows to call it because I've assigned the MenuPopup member of invokeTransportStreamToolsCommand to call it.

handleTransportStreamToolsCommandInvoked is called when the user clicks on the menu item. In this case, my code tries to activate the pane (which is referenced by name), if the pane can't be activated, then it means it probably isn't instantiated yet. We try to instantiate it here. Vegas knows to call this function because I told it to in the Invoked member of invokeTransportStreamToolsCommand.

When instantiating the control (which assumes you already have one, which you don't, but I'll explain it in forsight), we make an instance of our IDockView which will in the case be a class which inherits from Sony.Vegas.DockableControl.

We set the AutoLoadCommand to reference the invokeTransportStreamToolsCommand. I'm not 100% sure when this is used, but it appears to keep things in order in the Vegas UI.

We then inform vegas to load the dockView instance we've produced.

12) Right click the project and "Add/User Control"
At this point, you just start hacking to make something. Hello world is typically a good place to start. Make sure that the code I provided above is altered to reference your new class name (the namespace will be an issue as well)

13) View the code of the new control you've produced.
14) Change the class you inherit from, it was UserControl and will be DockableControl, it's important you provide a "using Sony.Vegas;" statement in the file to keep you sane.
P.S., I recommend you cut and paste the whole public partial class Foo : UserControl, then comment out the original one, you'll be switching between the two quite often since Designer only works on Form and UserControl.

15) Alter the constructor of the class to make sure the control becomes named, for example
public Foo : base("NameReferencedInFindDockViewAndActivateDockView")
{
InitializeComponent();
}

16) Override the "DefaultDockWindowStyle" property to define how you want your control to start. For example
public override DockWindowStyle DefaultDockWindowStyle
{
get { return DockWindowStyle.Docked; }
}

Vegas checks this value to see how it should initially display the control.

17) Override the "DefaultFloatingSize" property :
public override Size DefaultFloatingSize
{
get { return new Size(640, 480); }
}
I used 640x480, choose whatever size you want, it defines that if the user were to remove the control from the dock view, how big should it be initially.

Tips :

From this point, you should actually have a functional dockable window that you've written, the project should be setup so that you can just press F5 and Vegas will start up, then you can run the extension to debug it.

When you want to change the design of the view, open the code to the user control you've written and change the class inheritance back to UserControl, when you're done, change it back to DockableControl. I've actually made a little script in VS2005 which allows me to press Ctrl+9 to toggle it for me. I might release this someday.

BIG TIP!!!
Make sure that you remember that any time you even begin to imagine you're changing the timelines or project settings in any conceivable way, make sure to instantiate an UndoBlock class since Vegas DOES crash if you try to change the timeline without it from within DLLs.

I personally recommend in many cases using foreach() iterators instead of IEnumerator iterators for cycling through the many many collections you'll be using. My reasoning for this is that the big-O is constant for index accessors in lists within .Net, so you don't benefit a great deal from using IEnumerator and I just find foreach more pleasing to look at.

Since exceptions don't throw very nicely from within Vegas, I recommend that you stick one BIG try/catch around your code and use :
System.Diagnostics.Debugger.Break()
to force the debugger to break on the throw so you can actually evaluate the error expression.

I'll check back here occassionally while waiting for Sony to answer some of my questions, so please feel free to ask for more details on anything.
Rosebud wrote on 9/28/2007, 2:05 PM
Many Thx Darren,
This is a similar method from Jetdv.
I’m using another method with UserControl witch I don’t need switching to edit the GUI.
I’m not English and I'm not able to really describe my method so you can download a sample HERE. (Visual C# Express Project)

But with this method, I’m still having a problem to set the size of the DockableControl.
Please, see the Class1.cs > dockView.Size = new Size(640, 480);
This code don’t work and I don’t understand why.

TIA for your help.
Rosebud wrote on 9/30/2007, 1:39 PM
Problem solved:
dockView.DefaultFloatingSize = new Size (640,480);