Trouble modifying Vegas properties in C#

Cheesehole wrote on 6/29/2008, 4:17 PM
Hi guys - so I thought everything was going well with my first Custom Command. I can read properties and display them in my dockable script. But every time I try to modify anything in the Vegas project it throws an exception. For example if I try to add a marker:

System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at Sony.Vegas.IMarkerCOM.Add(Int64 pos, Int64 len, String label, UInt32& sessionID, Int32& typeIndex)
at Sony.Vegas.Marker.AddSelf(IMarkerCOM com)
at Sony.Vegas.BaseMarkerList`1.BaseAdd(T item)
at Sony.Vegas.BaseList`1.Add(T item)


I've tried to modify the project properties, add tracks, it's always the same result. CATASTROPHIC!!!

Has anyone seen this? Is it because I'm using VS2008? I'm trying to execute the following code in this case:

Timecode TC = new Timecode();
TC.Nanos = 10000;
String L = "Test";
Marker M = new Marker(TC,L);
myVegas.Project.Markers.Add(M);

Comments

Cheesehole wrote on 6/29/2008, 4:51 PM
Actually I can't even seem to add a simple video track

When I execute this code:
myVegas.Project.AddVideoTrack();

I get this error:

System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at Sony.Vegas.IProjectCOM.AddTrack(MediaType type, Int32& index, UInt32& trackID)
at Sony.Vegas.Track.AddSelf()
at Sony.Vegas.Tracks.BaseAdd(Track item)
at Sony.Vegas.Project.AddVideoTrack()


AHHH!!!!! ;)
JohnnyRoy wrote on 6/29/2008, 6:45 PM
Ben,

You should read the sticky post : What's new in Vegas Pro 8 (scripting). I know I had to read it several times and I still haven't absorbed all of the changes that were made. I keep finding new nuances every time I read it.

That post will show you that unlike Scripts, Commands must control their own Undo block. The example that's given is:


void HandleCommandInvoked(Object sender, EventArgs args)
{
using (UndoBlock undo = new UndoBlock("Sample Commands"))
{
// make your changes to the project here. in this case,
// the method call below will return false if no changes
// are made or the changes should be reverted.
undo.Cancel = !MakeProjectChanges();
}
}

The text in the UndoBlock("Sample Commands") will be displayed in the undo list in Vegas so try and make it something that will be useful to the end user (because they will see it).

So your code should look like:


void HandleCommandInvoked(Object sender, EventArgs args)
{
using (UndoBlock undo = new UndoBlock("Add Marker"))
{
Timecode TC = Timecode.FromNanos(10000);
String L = "Test";
Marker M = new Marker(TC,L);
myVegas.Project.Markers.Add(M);
}
}

~jr
Cheesehole wrote on 6/29/2008, 9:11 PM
Wow... so much to learn! So that's what I was missing... Thanks you are a life saver! I can't wait to try... it's been driving me nuts for hours!

You're right there is a lot of stuff I was wondering about in that sticky post.

Ben
Cheesehole wrote on 6/30/2008, 8:39 PM
Everything's working great now. I had to learn a lot to deal with the strict typing in C# and all the private protected internal stuff... I never learned to code properly. Intellisense makes it fun to learn though! I ran into a weird thing when I tried to create a WPF UserControl but I just need to add a special event handler to wait for certain libraries to be available during the load process... I'd like to tackle that because the graphical quality is a little lacking in the standard Form/Usercontrol stuff. But don't want to bite off more than I can chew... heh... thanks again.