[Vegas 13.0 Extension error] I can read, but can't write/edit

fould12 wrote on 3/9/2017, 9:37 AM

I'm using Windows 7 64-bit Ultimate edition

Here is my program code for C#:

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

namespace Example
{
    public class Example : ICustomCommandModule
    {
        protected Vegas myVegas = null;//Dockable edition

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

        CustomCommand myViewCommand = new CustomCommand(CommandCategory.View, "myViewCommand");

        public ICollection GetCustomCommands()
        {
            myViewCommand.DisplayName = "Hello World View";
            myViewCommand.Invoked += this.HandleInvoked;
            myViewCommand.MenuPopup += this.HandleMenuPopup;
            return new CustomCommand[] { myViewCommand };//Dockable edition
        }

        void HandleInvoked(Object sender, EventArgs args)
        {
            if (!myVegas.ActivateDockView("YTPMView"))
            {
                DockableControl dockView = new DockableControl("YTPMView");

                Button mbutton = new Button();
                    mbutton.Size = new Size(120, 40);
                    mbutton.Location = new Point(30, 30);
                    mbutton.Text = "This button";
                    mbutton.Click += new EventHandler(mbutton_Click);
                dockView.Controls.Add(mbutton);


                myVegas.LoadDockView(dockView);
            }
        }

        private void mbutton_Click(object sender, EventArgs e)
        {
            Project activeProject = myVegas.Project;
            try
            {
                activeProject.Tracks[0].Events[0].Start = startl;
            }
            catch(System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().ToString());
            }
        }

        void HandleMenuPopup(Object sender, EventArgs args)
        {
            myViewCommand.Checked = myVegas.FindDockView("YTPMView");
        }
    }
}

 

Specifically the problem is when I try this:

activeProject.Tracks[0].Events[0].Start = startl;

It gives back an error that gives the message "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

This only happens when I try to CHANGE things in the project (even using methods such as 'Copy()'); but when I just load data about the project (e.g., I get the start, length, and end times), it works normally.

What is going wrong? Am I doing something wrong?

Comments

Jam_One wrote on 3/9/2017, 1:57 PM

using Sony.Vegas;

Sure your Vegas 13.0 is of "Sony"?

 

fould12 wrote on 3/9/2017, 4:20 PM

Sure your Vegas 13.0 is of "Sony"?

 

I'm not sure what you mean; the Sony Vegas program 'vegas130.exe' I'm making this for is in the folder "C:\Program Files\Sony\Vegas Pro 13.0", so I think it's of Sony.

fould12 wrote on 3/10/2017, 10:53 AM

I found out what was wrong here: https://www.vegascreativesoftware.info/us/forum/software-works-as-script-but-not-a-extension-vegas-14--105749/#ca654391

Apparently, all Vegas parameters can only be modified after they are first enclosed in a Vegas undo block:

using ( new UndoBlock ( "Text that appears in the Undo dropdown list" ) )
{

activeProject.Tracks[0].Events[0].Start = startl;

}

After changing it to that it worked.

jetdv wrote on 3/11/2017, 10:38 AM

If you were changing many of them in a loop, make sure the "undoblock" is outside of the loop. Otherwise you will get one for every event changed instead of one for the entire process. For example, in my multicam tool, it creates one entry for "undo multicam" (not the exact wording I used) even though it may create hundreds of new event on a newly created track. You would not want hundreds of undo messages.