Scripting question

PaulieT wrote on 7/24/2025, 8:11 PM

Hi Everyone,

I'm writing a Sound Forge script and using a sample script as a basis. I'm using Sound Forge 10 in Windows 11, but the same thing appears in Sound Forge 17.

In the sample script there is a command "DPF" which obviously prints to the Sound Forge window.
DPF ("Template: '{0}'", vPreset);

There is also another command "GETARG" which obviously gets user input.
string szDir   = GETARG("dir", "");

I cannot find either command in the Sound Forge API Help (chm) file and neither are C#, or C commands.

Any suggestions as to what I am missing?

Thanks for your help,


 

 

Comments

SP. wrote on 7/25/2025, 6:08 AM

@PaulieT Usually the DPF and GETARG functions in the examples are placed at the bottom of the script. These are just there so you don't need to type ForgeApp.OutputText(String.Format()) in case of DPF() or perform length checks or null checks for arguments.
 

public static void DPF(string sz) {
  ForgeApp.OutputText(sz);
}


public static void DPF(string fmt, object o) {
ForgeApp.OutputText(String.Format(fmt, o));
}


public static void DPF(string fmt, object o, object o2) {
ForgeApp.OutputText(String.Format(fmt, o, o2));
}


public static void DPF(string fmt, object o, object o2, object o3) {
ForgeApp.OutputText(String.Format(fmt, o, o2, o3));
}


public static string GETARG(string k, string d) {
  string val = Script.Args.ValueOf(k);

  if (val == null || val.Length == 0)
    val = d;

  return val;
}


public static int GETARG(string k, int d) {

  string s = Script.Args.ValueOf(k);

  if (s == null || s.Length == 0)
    return d;
  else
    return Script.Args.AsInt(k);
}


public static bool GETARG(string k, bool d) {

  string s = Script.Args.ValueOf(k);

  if (s == null || s.Length == 0)
    return d;
  else
    return Script.Args.AsBool(k);
}


public static double GETARG(string k, double d) {

  string s = Script.Args.ValueOf(k);

  if (s == null || s.Length == 0)
    return d;
  else
    try {
      d = double.Parse(s);
    } catch {

    }

  return d;
}

They are basically there to save you from typing more code, but you don't need to use them.

PaulieT wrote on 7/25/2025, 3:54 PM

Thanks SP,

That helps a lot. However, where is ForgeApp.OutputText and where are these methods defined?

Thanks,
Paul

 

SP. wrote on 7/26/2025, 5:42 AM

@PaulieT For ForgeApp look under IScriptableApp

PaulieT wrote on 7/26/2025, 10:37 AM

Thanks SP,

I looked under IScriptableApp but did not see it, I even did a search in the Sound Forge Scripting API (CHM file) with no luck. Maybe I'm just overthinking the scripting interface.

Paul

SP. wrote on 7/26/2025, 10:55 AM

@PaulieT Here is a screenshot:

SP. wrote on 7/26/2025, 11:01 AM

@PaulieT By the way, if you write Sound Forge scripts in a Visual Studio project and include the Script dll (in my case it's Forge120.Script.dll inside the Sound Forge program directory) in your project, you get Intellisense code completion. This is very helpful and much handier than using the internal Sound Forge editor. No need to look up the API documentation all the time, because you cannot remember the names.

PaulieT wrote on 7/26/2025, 1:21 PM

Thanks SP,

I was literately searching for the text string "ForgeApp".

I'm currently using Visual Studio Code to work on Scripts. I've never actually used Visual Studio. I did use Atmel Studio (long before Microchip bought them) and I believe Atmel Studio was built on Visual Studio.

So, I just installed Visual Studio. I created a Test Project, added Forge100.Script.dll as an Assembly under Dependencies. All the Sound Forge apps show up in the Object Browser. When I loaded a demo script, I got a few errors. One of them is:

using System.Windows.Forms;

Obviously, I did something wrong!

Paul

 

 

 

SP. wrote on 7/26/2025, 1:35 PM

@PaulieT Ok, ForgeApp is the name of the variable. It's of class type IScriptableApp. You look under the class type for properties and methods. The name ForgeApp isn't relevant because you can name a variable as you want.

Can you add the Assembly System.Windows.Forms? See this screenshot.

PaulieT wrote on 7/26/2025, 1:47 PM

Hi SP,

I did not create a Windows Forms project. I just used the default "Console App".

 

SP. wrote on 7/26/2025, 2:07 PM

@PaulieT Then simply add it as a reference like shown in my screenshot. It's missing in standard console applications.

PaulieT wrote on 7/26/2025, 2:31 PM

I'm completely lost!

SP. wrote on 7/26/2025, 3:12 PM

@PaulieT No problem, you created a .NET Core project.

Basically, Microsoft had .NET only for Windows in the past. They developed a new version (called Core) which superseded .NET also works on other operating systems like Linux or Mac. The problem is, that WinForms is not compatible with .NET Core.

So you need to select to create a Windows Forms App (.NET Framework) or Console Applications (.NET Framework) and then select .NET Framework 4.8.