26.1 Introduction to Programming

Origin is designed to be a fully programmable software application. As you gain familiarity with Origin, you may want to customize Origin to meet your specific needs. Common customization needs include:

  • Adding functionality to Origin by creating new import, analysis, graphing, and export routines.
  • Automating routine data processing tasks.
  • Performing numerical computations and simulations in Origin.

Origin provides two types of programming environments, the LabTalk scripting language, and the more advanced Origin C programming language.

Programming Languages in Origin

Origin provides the following programming languages:

LabTalk is a scripting language that provides access to most of the functionality in Origin. One can access and change properties of various Origin objects such as worksheet columns and graph layers and data plots. In addition to access to objects in Origin, one can also access X-functions from LabTalk for performing advanced data processing tasks.

Origin C is a full featured high level programming language closely based on the ANSI C programming language syntax. In addition, Origin C supports a number of C++ features and a few C# features. Origin C provides full access to Origin's many data import, data handling, graphing, analysis, and export capabilities. Origin C can be combined with user interface controls such as buttons, toolbars and menu items, or by creating X-function based dialogs, or advanced dialogs and wizards created using the Developer Kit.

In addition to the two programming languages, Origin can also be accessed as an automation server. Client applications such as National Instruments LabVIEW, Microsoft Excel or custom VB/VC/C# applications can use methods and properties exposed by Origin to exchange data back and forth with Origin as well as send commands to be executed in Origin.

Which Language to Use and When

The choice of which language to use for programming in Origin is mainly a question of complexity of the task. For simple operations such as manipulating data in worksheet columns or performing simple analysis tasks such as smoothing or interpolating a dataset, LabTalk scripting is well suited. In fact, when performing column transformations using 'Set Column Values' dialog, the formula as well as the 'Before Formula Script' panel both use LabTalk syntax.

LabTalk script can be easily executed from the Command Window and Script Window, allowing for quick operations on data and other Origin objects. Multiple lines of script can be saved to a disk file, optionally organized as sections. The code in such files and sections can be called upon later for execution. LabTalk script can include calls to X-Functions that perform advanced data processing and analysis.

The analysis template feature in Origin 8 allows for creating a sequence of operations on the data including report generation, and such templates can then be opened programmatically from LabTalk and new data can be imported into the template to automatically update results. LabTalk scripts can thus be developed to perform batch processing of multiple files using an analysis template.

In short, if you are beginning to explore programming in Origin, it is typically good to start with LabTalk scripts.

As your Origin programming needs grow, and/or you move to more and more complex customization that involves more extensive coding, it would be more practical to switch to the Origin C programming environment. Origin C provides extensive access to all Origin objects and properties. Origin C code is organized as functions with support for passing arguments including various Origin objects. Origin C functions which are compiled to object code and then loaded and run inside of Origin. Origin C thus provides better reliability and management, for developing and debugging code involving larger scope and complexity.

Origin C is also the language used to create X-functions which are self-included XML files that can be loaded in Origin as a special type of global function. X-Functions provide user with a way to expand the functionality of Origin by adding custom data processing features. Custom tools can also be created using Developer Kit to build the dialog resources and then Origin C can be used to access such dialogs from within Origin.

If you are considering accessing Origin's data analysis and graphing abilities from an outside client application such as LabVIEW or Excel, you can access Origin as a Automation Server application, calling upon methods and properties exposed by Origin. One of the methods exposed is a way to send command strings to Origin for execution, which provides expanded access to Origin. Such command strings are Labtalk strings which could access a script file/section saved on disk, and script can call upon X-functions as well as pre-compiled Origin C functions to perform custom data analysis and graphing operations in Origin from the client application.