Community Forums Archive

Go Back

Subject:Turning scripts into libraries
Posted by: ciaranw
Date:7/19/2007 6:51:00 AM

I want to turn scripts into a libraries I can use from inside other scripts, so that I can build up a toolkit of libraries to simplify creating scripts for specific tasks.

Where do I start?

Subject:RE: Turning scripts into libraries
Reply by: _TJ
Date:7/23/2007 2:33:49 PM

Script libraries are .NET Assembiles (dll's). So you need to have a tool that will compile .NET and make assemblies.

You can do this will nothing but the the .NET runtime (that you have to install to get Scripting to work in Sound Forge). But it's hard to do this way. Lots of complex command lines, and a good understanding of the compile/link process as well as the mechanics of how .NET works. if you are a professional programmer or have equivalent skils, then let me know and I can give you some details to help get you oriented, but it's too much information to impart unless you have a lot of background already.

Otherwise, You will need Microsoft's Visual Studio .NET. or an equivalent. For Sound Forge 8.0. You need Visual Studio 2003, since that is the only one that will create .NET 1.1 assembiles, for Sound Forge 9, you can use that, or you can use Visual Studio 2005, which makes .NET 2.0 assemblies, but can't make .NET 1.1 assemblies.

Just create an empty .NET library (not application). Then you can drop a bunch of script files into it, give the methods in them all unique names. All of our samples have methods named Begin() or FromSoundForge(), so you will need to change those names so that they are all different from each other. All of our samples also have a class called EntryPoint, and you will need to give each one a different class name as well, Then you build your library, and copy it into the Sound Forge Script Menu folder.

Lets say you called it FRED.DLL.

Then you just add
using fred;
to the start of your Sound Forge script, and put FRED.DLL into the same folder as the script.

From then on you can call methods in FRED, from your script.

This is essentially what we do so that you can call Sound Forge Scripting methods: We compile them into a DLL, and we add
using SoundForge;
to the top of scripts so that we can call those methods.

We include in the Scripting SDK, a sample dll. It's the batch converter.

tj

Subject:RE: Turning scripts into libraries
Reply by: ciaranw
Date:7/31/2007 10:26:31 AM

Hi, thanks for replying.

I'm not a programmer, though I do have one working for me. If necessary he can help, or at least clarify terminology etc. I'm keen to learn for myself though, so I will press on for now...

I'm using the SharpDevelop IDE and have worked out how to create a library project and build a dll. I understand about making sure method and class names are unique.

I have created some test dlls, copied to various locations (Sound Forge program folder root, Script Menu, the subfolder of Script Menu where the calling script resides) and tried to reference them from within a script in the SF script editor. I get the following error:

Compiler error 0x80004005 on Line 4,7 : The type or namespace name 'SFScripts' could not be found (are you missing a using directive or an assembly reference?)

(SFScripts is my dll and also the namespace within it).

Is there something else SF needs to know, in order to include my dll when compiling the script?

Thanks for your help,
Ciaran

Subject:RE: Turning scripts into libraries
Reply by: ciaranw
Date:7/31/2007 10:32:21 AM

btw the line that error refers to is:

using SFScripts;

Subject:RE: Turning scripts into libraries
Reply by: _TJ
Date:8/7/2007 3:30:36 PM

Sound Forge uses the folder that the script resides in as the place to look for assemblies that are referenced by that script but are not part of the standard set of assemblies loaded automatically.

When you use the Script Editor window, the script doesn't have a folder (it lives only in ram, and not anywhere on disk) until you Save it. At that point,
if your assembly has a namespace that it the same as the assembly name, and lives in the same folder as the script, the assembly should be found by the compiler, and that error message should go away.

If you change the script aftering saving it, then the Script Editor goes back to using a RAM version of the script rather than the file on disk, and so, once again, the compiler doesn't know where ot look for your assembly. You must Save before you compile every time to avoid the compiler error.

If you are using Sound Forge 9, you can right click on the Open or Save toolbar buttons on the Script Editor window to get an options menu. The options menu will allow you to choose to automatically save the script before running it if it has changed. But beware! This option will overwrite the existing file without asking, making it easy to loose older versions of the script.

tj



Go Back