Scripting 3.3. Numeric queries

Now that you know how to script a menu command, and you know how variables work, you are ready to combine the two.

Suppose you have selected a Sound in the object list. One of the commands available in the Query menu is Get power.... When you choose it, you will see the following settings window:

When you click OK, something like the following will appear in the Info window:

This is the mean power of the whole Sound.

In a script, you want to use the value of this power in the script itself, not in the Info window, perhaps because you want to do computations with it or because you want to report the value with a nice text around it. This is how you do the latter:

power = Get power: 0.0, 0.0
writeInfoLine: "The power of this sound is ", power, " Pascal-squared."

The first line of this script executes the menu command Get power..., but puts the value 0.1350605005239421 into the variable power instead of into the Info window (the variable can have any name you like, as long as it starts with a lower-case letter and consists of letters and digits; see Scripting 5.1. Variables).

The second line then reports the value in the Info window, this time with a nice text around it:

Links to this page


© ppgb, January 11, 2014