Problem Creating CommandMarkers in 8.1

JasonG wrote on 1/13/2009, 12:02 PM
I'm trying to write a script that adds Text Command Markers to a project. I keep getting an error when I try to add the marker. I'm new to C# and vegas scripting, so I'm sure that I'm just doing something wrong, but I can't figure it out for the life of me.
Here's what I'm doing:

private void button1_Click(object sender, EventArgs e)
{
CommandMarkerList myClist = vegas.Project.CommandMarkers;
CommandMarker newMarker = new CommandMarker((Timecode.FromSeconds(0)), (new MarkerCommandType("Text")), "Test1", "Test");
myClist.Add(newMarker);
}

The error comes at the point where I try to add the newMarker to the CommandMarkerList. I didn't think I'd need this step, but just creating the newMarker doesn't seem to do anything. I'm guessing that I'm creating the marker incorrectly? Any help would be appreciated.

Comments

Rosebud wrote on 1/13/2009, 12:10 PM
You have to add an undo block.
See this post.

Edit: Oops sorry, I read too quickly...

Your script works fine for me (VP8.0c).
Which error are you getting ?
jetdv wrote on 1/13/2009, 3:56 PM
Try this:

vegas.Project.CommandMarkers.Add(newMarker);
JasonG wrote on 1/14/2009, 10:21 AM
Thanks Rosebud, adding an undo block did the trick. I'll have to give that sticky thread a read through. I never would have figured that out on my own.
jetdv wrote on 1/14/2009, 10:32 AM
If you're writing a Custom Command, modifications in Vegas MUST be in an "UndoBlock". Vegas is read-only unless you use the UndoBlock. The good thing is that YOU can specify the name that shows up in the undo list.

Standard scripts do not require the undo block.

Without knowing what kind of plugin you're writing (i.e. script vs custom command), it gets hard to diagnose what the issue may be.

This is an important post to read:
http://www.sonycreativesoftware.com/forums/ShowMessage.asp?MessageID=546252&Replies=2