1.1.1 Creating a Simple X-Function


X-Functions are created with X-Function Builder. You can open X-Function Builder by choosing X-Function Builder on the Tools menu or by pressing F10.

The X-Function Builder dialog is shown below.

Ocguide xfdialog default.png

Creating X-Function

The steps below will walk you through the creation of an X-Function that will perform the task of copying data from one column to another column.

  1. Start creating an X-Function by pressing F10 to open X-Function Builder.
  2. Name the X-Function "CopyCol" and add a second variable by right-clicking on the Variables list and choosing "Add variable". Change the variable names, labels, and other values to match the settings in the dialog below.
    Ocguide xfdialog.png
  3. After you make the necessary changes to the variables, save the X-Function by clicking the Save OXF file button Ocguide xfdialog savebutton.png. When the Save As dialog appears click the Save button.
  4. Click the X-Function Tree View button Ocguide xf treeview button.png to switch to tree view. Make sure the Labtalk check box is checked and the Auto GetN Dialog is set to Simple GetNBox, as below. Select the Labtalk check box to make it so the X-Function can be used in the Command Window. The Auto GetN Dialog provides the choice to use an X-Function without dialog or with dialog, as there are multiple different types.
    Ocguide xfsimpledialog treeview.png
  5. Now we need to write the Origin C code that will do the work for our X-Function. Click on the Code Builder button Ocguide xfdialog codebuilderbutton.png. This will open the X-Function in Code Builder where we can write our Origin C code. In the main function, add the following Origin C code:
    ocol = icol;
  6. Click the Compile button and then click the Return to Dialog button to go back to X-Function Builder. Click the Save OXF file button.

Using X-Functions

Now that we have successfully created our X-Function, we can test it.

  1. Create a new a worksheet with two columns. Fill column A with row numbers and select the whole column by clicking on its heading.
  2. In the Script or Command Window enter "CopyCol -d", without the quotes, and press Enter.
  3. When the dialog appears, keep the default values and click the OK button.

After the X-Function executes, the worksheet will contain a third column which will contain a copy of the data from column A.