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.
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.
For Set Column Values, you can now define the contents of the column formula box, Before Formula Scripts and Python Functions using LabTalk.
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. The current embedded Python version is version 3.8.3.
Origin 2021b includes numerous additions to the new originpro module that, with minimal coding, provides access to Origin workbooks, matrices and graphs, plus data frames and NumPy arrays. In addition, Intellisense (code autocompletion) has been added to the Python Console and the Python tab of Set Values.
Note: For more information on integrated usage of Origin and Python, see the Python book in the Origin Help Files.
Sample files can be found in the \Samples\Python folder of your Origin software.
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.
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.
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.