Struggling with project 'Test Script With Form'

Jack S wrote on 1/21/2023, 8:58 AM

@jetdv Edward, I'm wanting to get into scripting and I've made a little progress. However, I'm struggling with your tutorial on creating a form. The biggest problem is that I'm using Visual Studio 2019 which, in places is totally different to the version you are using. I managed to decipher the differences to get as far as adding the ScriptPortal.Vegas reference (which in VS 2019 appears to be called an Assembly). When I clicked Ok, an error window appeared.

The debug window then showed that the Launch option had reverted to default.
As you can see, the reference had been added.

I carried on adding the code as per your tutorial. I then found that the form had disappeared from the design window.
I'd appreciate any help you can give.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

Comments

jetdv wrote on 1/21/2023, 3:28 PM

@Jack S You have to be VERY careful picking the "starting point". I gave an example in the first "Custom Command" video which shows the proper item to pick when starting a new project under Visual Studio 2019.

Honestly, the easiest way is to start with my "sample project" file and then modify it for your needs:

http://www.jetdv.com/tutorial/Vegas/Vegas%20Base%20Project%20With%20Form.zip

The scriptportal.dll will certainly still be added under "references" which leads me to believe that you've chosen the incorrect "starting point" in VS2019. But I'm guessing yours is not using .NET 4.

I just did a test in VS2019. On the "Create a New Project" screen, I typed in "Form" in the box at the top. The second entry then indicated it was C# and .NET so I picked that one. On the next screen, it indicated it was .NET 4 which is correct for the scripts. Once it opened, it had a "References" where the ScriptPortal.DLL file could be added with the Form1.cs and Program.cs files so the Program.cs file could be removed as indicated in the video.

Jack S wrote on 1/22/2023, 8:27 AM

@jetdv Thanks for that info Edward. I watched you video but I couldn't get past first base. The version of .NET wasn't displayed as it was for you. I proceeded though and found under properties that the version being used was .NET 5.0. I opened the list but couldn't see 4.0, only 3.0 and 3.5. So I went ahead and installed the latest version of .NET 4. After a restart, I tried again. The list still didn't show 4.as an option.
I then went ahead and opened up your project. A message appeared in red in the Solutions window that indicated I should install extra components. So I clicked OK. After starting VS again and selecting the Forms template, I saw that there was a drop down list with .NET 4 option. I chose this and clicked create. I was then able to add the ScriptPortal reference OK. Things are looking up. I can now proceed to follow your tutorial.
I have to say, if you hadn't provided the link to that 'sample project' I wouldn't have known what to do.

Thanks again.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 1/22/2023, 11:18 AM

@jetdv Well, I'm well and truly 'up the creek without a paddle'. I now find that I can't build the project because the version of .NET installed is 4.8 and I can't select that in VS. I get the following error message:-

Build started...
1>------ Build started: Project: Test Script With Form, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3275: The primary reference "ScriptPortal.Vegas" could not be resolved because it has an indirect dependency on the assembly "ScriptPortal.MediaSoftware.clrshared, Version=20.0.0.326, Culture=neutral, PublicKeyToken=3cda94b1926e6fbc" which was built against the ".NETFramework,Version=v4.8" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3275: The primary reference "ScriptPortal.Vegas" could not be resolved because it has an indirect dependency on the assembly "log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
1>E:\Jack's Data\Tutorials\Vegas Pro Scripting\Test\Test Script With Form\Test Script With Form\Form1.cs(9,7,9,19): error CS0246: The type or namespace name 'ScriptPortal' could not be found (are you missing a using directive or an assembly reference?)
1>E:\Jack's Data\Tutorials\Vegas Pro Scripting\Test\Test Script With Form\Test Script With Form\Form1.cs(52,27,52,32): error CS0246: The type or namespace name 'Vegas' could not be found (are you missing a using directive or an assembly reference?)
1>E:\Jack's Data\Tutorials\Vegas Pro Scripting\Test\Test Script With Form\Test Script With Form\Form1.cs(15,16,15,21): error CS0246: The type or namespace name 'Vegas' could not be found (are you missing a using directive or an assembly reference?)
1>E:\Jack's Data\Tutorials\Vegas Pro Scripting\Test\Test Script With Form\Test Script With Form\Form1.cs(16,22,16,27): error CS0246: The type or namespace name 'Vegas' could not be found (are you missing a using directive or an assembly reference?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Unfortunately, there's no way of uninstalling 4.8 and installing 4.0.
So, my scripting education will be limited to simple, none interactive, projects.😢
 

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/22/2023, 1:15 PM

@jetdv Thanks for that info Edward. I watched you video but I couldn't get past first base. The version of .NET wasn't displayed as it was for you. I proceeded though and found under properties that the version being used was .NET 5.0. I opened the list but couldn't see 4.0, only 3.0 and 3.5. So I went ahead and installed the latest version of .NET 4. After a restart, I tried again. The list still didn't show 4.as an option.

If you don't pick the right entry, then .NET 4 won't show up. You have to be VERY careful which starting point you choose.

.NET 4.8 is fine. It doesn't have to be .NET 4.0. If you point to an OLDER version of the ScriptPortal.dll file, you may be able to use a lower version of .NET.

 

1>------ Build started: Project: Test Script With Form, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3275: The primary reference "ScriptPortal.Vegas" could not be resolved because it has an indirect dependency on the assembly "ScriptPortal.MediaSoftware.clrshared, Version=20.0.0.326, Culture=neutral, PublicKeyToken=3cda94b1926e6fbc" which was built against the ".NETFramework,Version=v4.8" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

This is saying that you've selected .NET 4.0 as the target. Change your project to use .NET 4.8 instead of 4.0 and it should work. The script portal file you are using is based on 4.8 so that's what your project also needs to be.

 

Jack S wrote on 1/23/2023, 8:06 AM

@jetdv Change your project to use .NET 4.8 instead of 4.0 and it should work.

Unfortunately, the .NET options in VS don't go above 4.7.2, and I don't know how to force VS to accept 4.8.

I tried to install 4.7.2 but Windows won't allow me to do so as I already have 4.8 installed.

I'll have to do some VS research to see if there's a way to update the target framework options.

If you point to an OLDER version of the ScriptPortal.dll file, you may be able to use a lower version of .NET.

Can you explain how I can do that? There's only one version of 'ScriptPortal.Vegas.dll' in the VEGAS directory.

Last changed by Jack S on 1/23/2023, 8:07 AM, changed a total of 1 times.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/23/2023, 9:55 AM

You would need an older version of VEGAS installed and use the dll from that version. I frequently use the VEGAS Pro 14 dll as it works in all versions through 20 and will compile with 4.0 chosen.

Did you go back and start with my base version? If 4.8 is installed, it really should show up in the list of options with all the other 4.x versions.

Jack S wrote on 1/23/2023, 11:04 AM

Did you go back and start with my base version?

No. Because I'd completed the project, apart from the build, I loaded that back in and attempted to change the target framework from there. I'll start from base and see how it goes. Also, I'll try the dll from Vegas Pro 17 (the oldest I have). Thanks for your patience. It's much appreciated.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 1/24/2023, 9:23 AM

@jetdv Success. I selected .NET 4.0 and used the ScriptPortal from VP17 and got Test Script With Form to work.

This was after VS2019 had updated, so I don't know which contributed to the solution.
Thanks again for your guidance. I can now proceed up the learning curve.

Last changed by Jack S on 1/24/2023, 9:24 AM, changed a total of 1 times.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/24/2023, 9:35 AM

The only issue with using the older DLL files is that any new options added to scripting won't be available to the script. But this hasn't been a serious issue. Most of my scripts are still based on VEGAS Pro 14 for the widest possible compatibility range.

Jack S wrote on 1/24/2023, 9:40 AM

The only issue with using the older DLL files is that any new options added to scripting won't be available to the script.

At my level, I don't think that will be a problem.🙂

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/24/2023, 10:08 AM

Looking at the project I started in VS2019 which you marked as "the solution" up above, I right-clicked the project name (WindowsFormsApp1) and chose "Properties" to open the configuration for the project. Opening the .NET dropdown, this is what I see:

Jack S wrote on 1/24/2023, 4:57 PM

This is what I get.

What version of VS are you using? I'm on version 16.11.23, the current one.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/25/2023, 9:06 AM

Mine says version 16.11.2. I do believe if you have .NET 4.8 installed, it should show up in that list.

On the right side of the about box, it also says Microsoft .NET Framework version 4.8.04084

 

Jack S wrote on 1/25/2023, 11:19 AM

Mine says 'Microsoft .NET Framework Version 4.8.09037. Seems queer that it knows I have 4.8, but doesn't show it in the selection list. I'm going to start your tutorial from scratch again to see if there's any change.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/25/2023, 1:18 PM

You might also try loading my base project listed above and see what shows there.

Jack S wrote on 1/26/2023, 4:37 AM

.NET Framework 4.6.1

 

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

Jack S wrote on 1/26/2023, 8:15 AM

I think it was the runtime. I'll investigate.

Meantime I've had some success with a forms script I wanted to produce. I wanted to modify the script that applies fades to selected events, so that a form would appear where I could enter the fade length in frames. It sort of works. It applies the correct length fades to any selected event, but only after I exit the form. Your script that selects regions, selects the regions as soon as you click the button. I've listed the code below. It hasn't got any error trapping yet. Can you look at it and tell me where I've gone wrong?
Another thing. If Vegas is open, I can't rebuild the script because the dll can't be overwritten. I have to close VP down every time I want to test the script. Is there a way around this?

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 ScriptPortal.Vegas;

namespace Apply_Fades_02
{
    public partial class Form1 : Form
    {
        public Vegas myVegas;
        public Form1(Vegas vegas)
        {
            myVegas = vegas;
            InitializeComponent();
            udbox.Minimum = 1;
            udbox.Maximum = 75;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                foreach (TrackEvent myEvent in myTrack.Events)
                {
                    if (myEvent.Selected)
                    {
                        myEvent.FadeIn.Length = Timecode.FromFrames((int)udbox.Value);
                        myEvent.FadeOut.Length = Timecode.FromFrames((int)udbox.Value);
                    }
                   
                }
            }
        }
    }
}

public class EntryPoint
{
    private static Apply_Fades_02.Form1 form;
    public void FromVegas(Vegas vegas)
    {
        form = new Apply_Fades_02.Form1(vegas);
        form.ShowDialog();
    }
}

 

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/26/2023, 8:29 AM

Try this - change:
 

        private void button1_Click(object sender, EventArgs e)
         {
             foreach (Track myTrack in myVegas.Project.Tracks)
             {
                 foreach (TrackEvent myEvent in myTrack.Events)
                 {
                     if (myEvent.Selected)
                     {
                         myEvent.FadeIn.Length = Timecode.FromFrames((int)udbox.Value);
                         myEvent.FadeOut.Length = Timecode.FromFrames((int)udbox.Value);
                     }
                 }
             }
         }

 

to:
 

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                foreach (TrackEvent myEvent in myTrack.Events)
                {
                    if (myEvent.Selected)
                    {
                        myEvent.FadeIn.Length = Timecode.FromFrames((int)udbox.Value);
                        myEvent.FadeOut.Length = Timecode.FromFrames((int)udbox.Value);
                    }
                }
            }
            myVegas.UpdateUI();
        }

Of course you can't do anything else with the timeline until you close the window anyway. Unless you're just wanting to see the results and then change them again immediately, that's the only way I can see it needing this extra line.

Jack S wrote on 1/26/2023, 9:06 AM

Brilliant! That's done it. It shows me the result before I close the form. Thanks a lot. I must try and digest the API document, although it's not going to be easy.

Any idea why I need to close VP down to rebuild the dll?

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 1/26/2023, 10:44 AM

Because VEGAS keeps the DLL "open" in case you want to run it again. Once it's been started once, VEGAS must be closed to release the lock it puts on the file.

That one line basically tells VEGAS to "refresh the screen now".

If you want the window to be able to stay open all the time, look at the "Custom command" series.

Jack S wrote on 1/26/2023, 10:48 AM

Thanks Edward, I'll do that.

Thanks for your patience.

My system
Dell XPS 8700 (I know, it's a little outdated)
Windows 10 Home (x64)
3.1 GHz Intel Core i5-4440
16GB RAM
NVIDIA GeForce GTX 1050 Ti display adapter
System drive Samsung SSD 850 EVO 250GB

Camcorder
SONY Handycam HDR-XR550VE