20 Programming in Origin
As you gain experience with Origin, you may want to access Origin features programmatically, add your own custom routines and tools, or communicate with Origin from other applications. This chapter outlines basic programming options available in Origin. For more detailed information, see the following Origin programming-related resources:
- Programming documentation including guides, language references, and examples are available from the Help menu in the product.
- Online programming documentation is available at www.originlab.com/doc.
- You can typically locate online programming pages by performing a web search from your browser using phrases such as: labtalk importing , originc interpolate, or labview origin send data.
- An Origin Programming Forum can be found at www.originlab.com/forum.
- Sample files for LabTalk, Python, COM Server and Client, etc. can be found in the \Samples folder of your Origin software.
LabTalk is a scripting language that provides access to most of Origin's functionality. With LabTalk you can access and change properties of Origin objects such as worksheets, columns, graph layers, and data plots. LabTalk script can include calls to X-Functions to perform advanced data processing and analysis.
There are many options for executing your LabTalk scripts. Multiple lines of script can be organized as sections in a file, and those individual sections can be executed from the user-interface at the command prompt in the Script Window or Command Window; from buttons added to worksheets and graphs; from included or custom-made toolbar buttons; or from custom menu commands.
Origin 2022b improvements to LabTalk:
- Support for "substituting" cell Notes in graph legend and text objects using @WN (e.g. %(1, @WN, B, 3) for Note in col(B), 3rd cell of 1st plot's source worksheet).
- Control display of sparklines with new LabTalk System Variable @SPK (0 = (default) no change, 1 = display only existing, 2 = can add, but load with none, 3 = no add, load with none).
- Improve text editing in Notes window: support moving cursor to matching brace/parenthesis using CTRL+K, CTRL+B.
- Layer object support for changing XY mapping of the matrix object.
The following "mini-tutorial" will demonstrate adding a button object to a worksheet, associating a short LabTalk script with the button, then using the button to execute the script and perform a basic statistical calculation while writing the results to the worksheet.
- Run Origin and start a new project by clicking the New Project button on the Standard toolbar.
- Click Data: Import from File: Single ASCII and browse to the file \Samples\Graphing\Box Chart.dat. Select the file and click Open. The file is imported into the active worksheet window.
- With the worksheet window active, click Format: Worksheet. In the Worksheet Properties dialog, click the Size tab and set Gap from Top to 25, then click OK. A gap is added to worksheet window.
- Click the Text Tool on the Tools toolbar. Click inside the gap that you just added and type "Add Mean Label Row" into the text object. Click outside the text object to exit edit mode.
- Right-click on the text label and select Properties.... Choose Programming Control tab, set Script Run After to Button Up. Copy and paste the following script into the text box:
wks.userParam1 = 1;
wks.userParam1$ = "Mean";
for (int ii = 2; ii <= wks.ncols; ii++)
range rr = $(ii);
Col($(ii))[D1]$ = $(mean(rr),.2*);
- Click OK to apply settings and close the Text Object dialog box. Note that your text object now looks like a button.
- Click the button. Note that a new header row labelled "Mean" is added to the worksheet and the mean value of each column of data is written to the Mean row cell above the corresponding column.
Note: For more information on LabTalk, Origin's built-in scripting language, please consult your product documentation at Help: Programming: LabTalk.
Sample files can be found in the \Samples\LabTalk Script Examples folder of your Origin software.
Origin provides an embedded Python environment so that you can run Python in Origin. Origin supports command line execution of Python code from the Python Console or Origin's Code Builder IDE. As of September 2021, the embedded Python version is version 3.8.3.
Python support improvements in Origin 2022b:
- Added a function
evaluate_FDF(strFFname, indepvars, parameters) to call a fitting function from Python.
- Added package version checking to
pip -chk and
pip -chk1 (e.g.
pip -chk emd==0.4.0; // install emd version 0.4.0 only).
There is an API for calling Origin from Python. See note under Automation Server, below.
Origin supports running R commands in the Origin environment. You can issue R commands in the Script Window or from the built-in R Console, or you can run .R files. All releases of R are supported up through version
From Origin, you can connect with R in two ways:
- R. Installed on your local computer.
- Rserve. Installed on a remote PC.
The MATLAB Console allows Origin users to issue MATLAB commands from Origin, and to transfer data between the two applications either using a graphical interface or using a command line.
- The Console requires both Origin and MATLAB be installed on the same computer.
- Origin also supports importing MATLAB (MAT) files from disk. There are two import routines, the older Data: Import from File and the new Connector-based Data : Connect to File: MATLAB. Importing MAT files does not require that MATLAB be installed.
Note: For more information on the MATLAB Console, refer to the Origin Help file (MATLAB Console.
The <Origin Program Folder>\Samples\COM Server and Client\MATLAB subfolder contains an example (CreatePlotInOrigin.m, CreatePlotInOrigin.OPJ) that illustrates how to connect to an Origin COM server from a MATLAB client (requires MATLAB).
Origin C is a full-featured high-level programming language based on the ANSI C programming language syntax. Origin C also supports a number of C++ features and a few C# features. Origin C provides access to all aspects of Origin including data import, data handling, graphing, analysis, and exporting. You can access Origin C functions from interface controls such as buttons, toolbars, and menu items, using LabTalk script.
Origin C is organized as a set of functions with support for passing arguments. Origin C functions are compiled to object code and then loaded and executed inside of Origin. Origin C provides increased reliability and manageability for developing and debugging code of greater scope and complexity.
Origin C also provides access to the NAG Numerical Library functions included in your Origin installation. NAG functions provide you with a large selection of algorithms for performing computations ranging from simple statistics and Fourier transforms to linear algebra and multivariate analysis. Origin currently supports NAG Library Version Mark 26.1.
Origin C improvements for 2022b:
- Add function to matrixbase class for importing ASCII strings; with support for LF/CRLF, specify token separator and missing value.
- Add global function to get data range from name.
- Add function Worksheet class to get list of cells with Notes.
- Support for getting Notes embedded in worksheet.
Note: For more information on Origin C, please refer to the Origin C documentation:
Help: Programming: Origin C
There you will find usage information, a language reference, developer notes, examples, etc.
Sample files can be found in the \Samples\Origin C Examples folder of your Origin software.
An X-Function is a self-contained XML file that can be loaded in Origin as a special type of global function. Origin C is the language used to create X-Functions. X-Functions provide a way to expand the functionality of Origin by adding custom data processing features. Many of the built-in tools in Origin are based on X-Functions. Once an X-Function has been created, it can be accessed from anywhere in the interface that allows for script execution, such as the script window, toolbar buttons, or custom menu items.
Note: For more information on X-Functions, please refer to your product documentation that is installed with your software:
Help: Programming: X-Functions
There, you will find information on creating and using X-Functions, a language reference, and tutorials.
Automation Server. Client applications such as National Instruments™ LabVIEW™, Microsoft Excel, Python, or custom VB/VC/C# applications can exchange data with Origin, and can also send commands to be executed within Origin.
Origin can be used as an
Note: For more information on Origin's Automation Server functionality, refer to the product documentation installed with your Origin software:
Help: Programming: Automation Server.
There you will find examples and language reference information.
Sample files can be found in the \Samples\COM Server and Client folder of your Origin software.
National Instruments™ LabVIEW™ is widely used for data collection. For example, many instrument and sensor vendors provide LabVIEW drivers for acquiring data. Once the data is collected, the end user will need to graph and analyze the data, and create reports for presentation. Origin provides powerful data analysis and graphing tools, including the Analysis Template feature, which allows for repeat analysis on newly acquired data. The ability to communicate between LabVIEW and Origin can thus greatly improve the efficiency of post-acquisition analysis and presentation.
Origin ships with a collection of LabVIEW sub-VIs. LabVIEW users can simply incorporate these custom sub-VIs in their main LabVIEW application to communicate seamlessly with Origin.
For Origin 2022b, the "Close References" application control is added to all Samples\COM Server and Client\LabVIEW .vi files. Copy these samples to LabVIEW using the Origin menu Tools: Copy Origin Sub-VI LabVIEW vi.lib\addons.
Note: For more information on Origin-LabVIEW connectivity, see the product documentation installed with your Origin software:
Help: LabVIEW VI
Examples and tutorials are provided.
Orglab is a freely distributed component DLL for directly creating or reading Origin Project (.opj) and other Origin file types (.ogg, .ogw and .ogm). It is available as a free download. An Origin license is not required to use Orglab. Typical use of Orglab is for instrument manufacturers and other third-party vendors to allow their frontend software to output data as Origin files.
The Orglab module is available for both 64-bit and 32-bit systems. To find out more about Orglab and to download the Orglab module, go to the Products > Orglab page of www.originlab.com.