# 2.4.1.3 X-Function Execution Options

## X-Function Option Switches

The following option switches are useful when accessing X-Functions from script:

Switch Full Name Function
-cf -- Copy column format of the input range, and apply it to the output range.
-d -dialog Brings up a dialog to select X-Function parameters.
-db -- Variation of dialog; Brings up the X-Function dialog as a panel in the current workbook.
-dc IsCancel -- Variation of dialog; Brings up a dialog to select X-Function parameters. Set IsCancel to 0 if click the OK button, set to 1 if click the Cancel button. When clicking the Cancel button, no error message like #User Abort! dumps to Script Window and the script after X-Function can be executed.
-e -- Open the X-Function in the X-Function Builder. This works the same as the edit -x command.
-h -help Prints the contents of the help file to the Script window.
-he -- Prints the contents of script example to the Script window.
-hn -- Loads and compiles the X-Function without doing anything else. If the X-Function has already been compiled and loaded, it will do nothing.
-hs -- Variation of -h; Prints only the Script Usage Examples.
-ht -- Variation of -h; Prints only the Treenode information, if any exists.
-hv -- Variation of -h; Prints only the Variable list.
-hx -- Variation of -h; Prints only the related X-Function information.
-r <option> -recalculate Specify the recalculation mode: 0 = none; 1 = auto; 2 = manual. Example here.
-s -silent Runs in silent mode; results are not sent to Results log.
-sb -- Variation of -s; suppresses error messages and Results log output.
-se -- Variation of -s; suppresses error messages, does not suppress Results log output.
-sl -silent Same as -s.
-sr

(Origin 2016 SR1)

-- Variation of -s; suppresses result messages to the script window.
-ss -- Variation of -s; suppresses info messages to the script window.
-sw

(Origin 2016 SR1)

-- Variation of -s; suppresses warning messages to the script window.
-t <Name> -theme Uses the designated preset theme.

Recalculate is not supported when <input> is used an an <output>.

For options with an existing Full Name, either the shortened switch name or the full name may be used in script. For instance, for the X-Function smooth,

smooth -h

is the same as

smooth -help

## Examples

### Using a Theme

Use the theme named FivePtAdjAve to perform a smoothing operation on the XY data in columns 1 and 2 of the active worksheet.

smooth (1,2) -t FivePtAdjAve

Note: A path does not need to be specified for the theme file since Origin automatically saves and retrieves your themes. Themes saved in one project (*.OPJ) will be available for use in other projects as well.

### Setting Recalculate Mode

Set the output column of the freqcounts X-Function to automatically recalculate when data in the input column changes.

freqcounts irng:=col(1) min:=0 max:=50 stepby:=increment inc:=5
end:=0 count:=1 center:=1 cumulcount:=0 rd:=col(4) -r 1;
// Set Recalculate to Auto with '-r 1'.

### Open X-Function Dialog

While running an X-Function from script it may be desirable to open the dialog to interactively supply input. In this simple example, we perform a smoothing operation using a percentile filter (method:=2) and specifying a moving window width of 25 data points. Additionally, we open the dialog (-d) associated with the smooth X-Function allowing the selection of input and output data, among other options.

smooth method:=2 npts:=25 -d

### Copy Format from Input to Output

Use an FFT filter with the -cf option switch to format the output data to match that of the input data:

// Import a *.wav file; imported *.wav data format is short(2).
fname$= system.path.program$ + "Samples\Signal Processing\sample.wav";
newbook s:=0; newsheet col:=1; impWav options.SparkLines:=0;
string bkn$=%H; // By default, all analysis results are output as datatype double. // -cf is used here to make sure the output data to be short(2) fft_filters -cf [bkn$]1!col(1) cutoff:=2000
oy:=(<input>,<new name:="Lowpass Sound Frequency">);