11.3.2 Introduction to X-Functions

Summary

X-Functions provide a structured programming environment that offers a framework for building Origin tools. Different from the simple GetN box, creating tools by using X-Functions allows the user to focus on the actual data processing code and not have to worry about codes for the user interface.

Most of the dialogs/functions in Origin 8 are X-Functions, and many of them can be run from both menu and command line mode. The flexibility of running X-Functions makes them an attractive approach to customizing Origin

Minimum Origin Version Required: Origin 8.0 SR0

What you will learn

  • How to create an X-Function
  • How to make the X-Function script accessible
  • How to use the X-Funciton in dialog mode

Create an X-Function

  1. Select Tools: X-Function Builder or press F10 to open the X-Function Builder dialog
  2. Set Name, Label and Data of the 1st variable as ix, Source and <active>
  3. Right click in the list panel and select Add Variables from the context menu.
  4. Set Name, Label, Input/Output and Data of the 2nd variable as ox, Destination, Output and <new>
  5. Select File:Save to save the x-function as vcopy
    Vcopy.png
  6. Click Button Code Builder.png to open Code Builder
  7. Add the following codes in the vcopy function in code builder
void vcopy(const vector& ix, vector& ox)
{

	if (!ix || !ox)
            XF_THROW(CER_NO_DATA);

        ox = ix;	
    
}

Making the X-Function Script Accessible

  1. Click the Return to Dialog button in Code Builder
  2. In the X-Function Builder, save your changes Button Save Project.png
  3. Open the X-Function in Tree View by clicking TreeView.png
  4. Open the Usage Context branch. Make sure the Labtalk check box is selected
    Vcopy lt.png
  5. Save the x-function and close the X-Function Dialog
  6. Fill column(A) with row numbersw in the active worksheet (Highlight column(A), right-click and select Fill Column with: Row Numbers)
  7. Type the following script in the command window, Column(A) will be copied to Column(B)
    vcopy col(a) col(b)

Using the X-Function in Dialog Mode

  1. Open the X-Function Dialog and open VCOPY.OXF in Tree View
  2. Open the Usage Context branch
  3. Open the Menus branch, make sure Simple GetNBox is selected from the Auto GetN Dialog list box
    Vcopy smpdlg.png
  4. Save the x-function and close the X-Function Dialog
  5. Type following script in the command window, Dialog of VCOPY.OXF will be opened
    vcopy -d
    Vcopy dlg.png