This command defines a macro called macroName, and associates it with the given script. MacroName can then be used like a command, and invokes the given script. To see the script associated with a defined macro, use:define macroName. Macros can take up to five arguments. Use the %1, %2, %3, etc., notation within the script to indicate that the macro expects one or more arguments. A macro can accept a number, string, variable, dataset, function, or script as an argument, but all arguments are passed as strings. These are similar to MS-DOS batch command arguments. If arguments are passed to a macro, the macro can report the number of arguments using the macro.nArg object property.


define macroName (script)


Example 1

The following script defines the autoexec macro to create a new Origin worksheet from the ORIGIN.OTW template.

def autoexec { window -T Data Origin; };

Example 2

The next script defines a macro that uses a loop to print a text string three times.

def hello 
      loop (ii, 1, 3) 
            { type "$(ii). Hello World"; };

Once the hello macro is defined, typing the word hello in the Script window results in the printout:

1. Hello World

2. Hello World

3. Hello World

Example 3

The following script defines a macro named abc that expects a single argument. The given argument is then multiplied by 2, and the result is printed.

def abc { type "$(%1 * 2)"; };

If you define this macro (previous example) and then type the following in the Script window:

abc 5

Origin responds: 10

You could modify the abc macro (previous example) to take two arguments:

def abc { type "$(%1 * %2)"; };

Now, if you type the following in the Script window:

abc 5 4

Origin responds: 20