Bug - Vegas.Project not set in event handlers in non-modal Windows.Forms Forms

nolty wrote on 11/17/2004, 2:07 AM
Hi all --

In the following script, the reference to Sony.Project at initialization time succeeds, but when the event handler is called a runtime error results from the attempt to reference Sony.Project. However, if you change the line "theForm.Show" to "theForm.ShowDialog" (which makes the form modal), the reference succeeds.

import System.Windows.Forms;
import Sony.Vegas;

MessageBox.Show(Vegas.Project.FilePath);
var theForm : tmpForm = new tmpForm();
theForm.Show();

class tmpForm extends Form {
function tmpForm() { // constructor
this.Width = 100;
this.Height = 100;

var btnName = new Button();
btnName.Location = new System.Drawing.Point(20,20);
btnName.Text = "See Project Name";
btnName.add_Click(btnNameClickHandler);
this.Controls.Add(btnName);
}

protected function btnNameClickHandler(o: Object, e : System.EventArgs) {
MessageBox.Show(Vegas.Project.FilePath);
}
}

Comments

rcampbel wrote on 11/17/2004, 1:23 PM
This is because when you use Show, execution continues at the next statement so the script actually exits. With ShowDialog, execution does not continue until the form closes.

You could work around this by holding on to the vegas reference in your form by creating a variable in your form and assigning vegas to it:

var vegas = Vegas;

Then you would use vegas instead of Vegas.

However, be aware that there are other issues with using nn-modal scripts such as losing the undo capability. Vegas creates an undo point based upon what changed between starting the script and the script ending. I don't think that Sony is supporting non-modal scripts at this time.

Randall
SonyPJM wrote on 11/22/2004, 9:17 AM

Randall is correct, you should not use non-modal forms. Hopefully you
can do what you need by calling ShowDialog rather than Show.

If you attempt his suggested work-around, problems are indeed likely
to occur... especially if your code attempts to change any project
data after the script completes.

In the future, leaving resources around after a script completes (in a
non-prescribed way) is less likely to work because there's a very good
chance Vegas will run scripts in their own app domain and dispose of
it when the script is complete... this will kill off any non-modal
forms.

The good thing about running scripts in their own app domain is that
it fixes the problem that developers can not recompile assemblies used
by a script without quitting Vegas first :-).