"Hello World" Windows Forms - Input to Script

amendegw wrote on 9/11/2011, 4:47 AM
I'm just getting my feet wet in Vegas Scripting. As a matter of fact, my first venture in this area was here: Uncheck 'Maintain Aspect Ratio' in Bulk?

As a learning experience, I'd like to use a Windows Form to input user selected values to the script. I can display the form, but I'm getting all confused with flow of the code.


So, my question is... Can anyone post a "Hello World" program that displays a Windows Input Form from within a Vegas Script? I think what I'm looking for is two code blocks: 1) Windows Form code, & 2) C# Class code (i.e. EntryPoint) that interacts with Vegas.

I have Visual Studio 2010.

TIA,
...Jerry

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9

Comments

jetdv wrote on 9/11/2011, 7:42 AM
Here's a basic c# script that does nothing but gets the Vegas variable set to "myVegas" which you can then use to access Vegas and includes many "using" lines - most of which may not be needed.

To get input, you then have to create a form in the script and then display that form. You can either build it visually in Visual Studio and then just call that form or you can build it via code within your script.



using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Sony.Vegas;

public class EntryPoint
{
Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;


}

}
amendegw wrote on 9/11/2011, 2:36 PM
Okay, let me try to be more specific.

Let's say I create a Windows Form using the Visual Studio designer. The only thing it has is a button. When clicked the button should show the Vegas Version.

Here's the class EntryPoint code which works fine to display the Form:

Edit: Major revisons to the post below to clarify the post:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;

namespace SetAspectRatio
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
// What Code goes here to show my Vegas Version???
// MessageBox.Show(?????.Version);
}
}

public class EntryPoint
{
Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;
Form1 form1 = new Form1();
form1.Show();

}
}
}

I cannot display the Vegas Version. What code to insert into button1_Click() ???

...Jerry

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9

JohnnyRoy wrote on 9/11/2011, 10:08 PM
Try doing something with the results of the form. Like this:

public void FromVegas(Vegas vegas)
{
Form1 form = new Form1();
if (DialogResult.OK == form.ShowDialog())
{
// do something with the forms data
}
}

~jr
amendegw wrote on 9/12/2011, 4:55 AM
Wait! Stop the music. i think I've got something that works! Here's the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;


namespace SetAspectRatio
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(EntryPoint.myVegas.Version);
}

private void cancel_Click(object sender, EventArgs e)
{
this.Close();
}
}

public class EntryPoint
{
public static Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;
try
{
Form1 form1 = new Form1();
if (DialogResult.OK == form1.ShowDialog())
{
// do something with the forms data
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}

What I needed was to declare a public variable and process that in my button click event.

Is this the best way? I dunno. In any case, I'll keep fiddling and see what I come up with.

Thanks to all!
...Jerry

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9

amendegw wrote on 9/12/2011, 9:18 AM
Well, it's pretty obvious I'm a real novice in this area, but thru a lot of trial-and-error and help from JR & Ed I finally got my generalized case of a script to set aspect ratios to work.

There may be plenty of stuff wrong with what I've done, but I'll post my VS2010 project here so that others might get past all my trial-and-error.

Also, if others see major errors in the way this is done, I'd be interested in getting that feedback as well.

Here's the bare .dll: SetAspectRatio.zip
Here's the Visual Studio 2010 Project: SetAspectRatioVS2010.zip
Also, consistent with the original request, here's a Hello World Project: HelloWorldVS2010.zip

...Jerry

System Model:     Alienware M18 R1
System:           Windows 11 Pro
Processor:        13th Gen Intel(R) Core(TM) i9-13980HX, 2200 Mhz, 24 Core(s), 32 Logical Processor(s)

Installed Memory: 64.0 GB
Display Adapter:  NVIDIA GeForce RTX 4090 Laptop GPU (16GB), Nvidia Studio Driver 566.14 Nov 2024
Overclock Off

Display:          1920x1200 240 hertz
Storage (8TB Total):
    OS Drive:       NVMe KIOXIA 4096GB
        Data Drive:     NVMe Samsung SSD 990 PRO 4TB
        Data Drive:     Glyph Blackbox Pro 14TB

Vegas Pro 22 Build 239

Cameras:
Canon R5 Mark II
Canon R3
Sony A9