1.16 Accessing X-Function

Origin has many built-in X-Functions for handling a variety of tasks. X-Functions can be called from both LabTalk and Origin C. This Section will show you how to call X-Functions from Origin C by using Origin C's XFBase class. This mechanism also can be used in calling one X-Function in another X-Function.

The XFBase class is declared in the XFBase.h header file located in the Origin C System folder. The XFBase.h header file is not included in the Origin.h header file so it has to be included separately in any Origin C file for the use of XFBase class.

#include <XFBase.h>

Calling the impFile X-Function From Origin C

The procedure to use X-Functions in Origin C is as following:

  1. Declare an object that is to be constructed from a specified X-Function
  2. Assign arguments using the SetArg options from the X-Function object
  3. Execute the X-Function using the Evaluate method of the X-Function object

The following Origin C code defines a general function for importing files into Origin. The function has two arguments: data file name and import filter file name. Additional arguments of the impFile X-Function will use their default values.

bool call_impFile_XF(LPCSTR lpcszDataFile, LPCSTR lpcszFilterFile)
{
    string strDataFile = lpcszDataFile;
    string strFilterFile = lpcszFilterFile;

    // Create an instance of XFBase using the X-Function name.
    XFBase xf("impFile");
    if (!xf)
        return false;

    // Set the 'fname' argument.
    if (!xf.SetArg("fname", strDataFile))
        return false;

    // Set the 'filtername' argument.
    if (!xf.SetArg("filtername", strFilterFile))
        return false;

    // Call XFBase's 'Evaluate' method to execute the X-Function
    if (!xf.Evaluate())
        return false;

    return true;
}

The following Origin C code shows how to call the call_impFile_XF function defined above and use it to import an image file.

// Import the Car bitmap located in Origin's Samples folder.
string strImageFile = GetAppPath(TRUE) +
    "Samples\\Image Processing and Analysis\\Car.bmp";

// Import the bitmap using the Image import filter.
string strFilterFile = GetAppPath(TRUE) + "Filters\\Image.oif";

// Call the function that will use the impFile X-Function.
call_impFile_XF(strImageFile, strFilterFile);
Note:
  1. For more example on accessing X-Function, see Help: Programming > Origin C > Examples > Accessing X-Functions > Accessing X-Function
  2. For more information on X-Function, see Help: X-Functions