2.5.1.13 On Starting or Exiting Origin

Defining Global Constants, Variables and Functions

Use the [Startup] section of the Origin.ini to define global constants, variables and functions for use any time you run Origin.

See these topics for more information on scope:

Defining global constants and variables

See FAQ-286 for information on defining constants and variables for use across Origin sessions.

Defining a global function

  1. If Origin is running, exit the program.
  2. Start a fresh page in a text editor (e.g. Notepad) and enter the following information:
  3. [Main]
    @global = 1;
    // This function calculates the cube root of a number
    function double dCubeRoot(double dVal)
    {
        double xVal;
        if(dVal<0) xVal = -exp(ln(-dVal)/3);
        else xVal = exp(ln(dVal)/3);
        return xVal;
    }
    @global = 0;
  4. Name and save the file to your the User Files Folder (UFF), using an .OGS file extension (e.g. myLTFuncs.ogs).
  5. Browse to your Origin.ini file in your UFF and open this file in your text editor.
  6. Locate the [Startup] section of the file and add the name of the .OGS file you just created using the following form:
    FileN=myLTFuncs.ogs

    ... where N is 1,2,3,etc.

  7. Save your changes to Origin.ini.
  8. To check the availability of your function, run Origin, open the Script Window and enter the name of the function, followed by a value in parentheses and "=", then press ENTER.
    dCubeRoot(8)=

    Origin returns:

    dCubeRoot(8)=2

See this topic for more information on the Scope of Functions.

Using OEvents.ogs to Trigger Events

When the Origin application is launched, there are multiple events that are triggered. Your LabTalk script can be set to execute with each event using the OEvents.OGS file. This OEvents.OGS file includes several sections that indicate when to run the script, such as, [AfterCompileSystem], [BeforeOpenDoc], and [OnExitOrigin].

The following example demonstrates cleaning the history panel of Command Window on existing Origin.
(Note that Origin C functions can not be run in the [OnExitOrigin] section. If you want to trigger events on exiting Origin, always use LabTalk commands.)

  1. Copy the OEvents.OGS file from the Origin EXE folder to your User Files Folder. Alternatively, when opening the file from the EXE folder just make sure to then save it to your User Files Folder.
  2. In the section named [OnExitOrigin], add the following script:
    // Delete the files, which keep the history of command window, from the User File folder
    del -f "%YUpDown_Buffer.txt";
    del -f "%YLTHistory.txt";
  3. To run sections in OEvents.OGS, you also need to edit the Origin.ini file in your User Files Folder. Close Origin if running, and then edit your Origin.ini and uncomment (remove the ";") in the line under the [Config] section, so that it is as below:
    Ogs1 = OEvents
    ; Ogs2 = OEvents
    ; Origin can trigger multiple system events
    ; Uncomment this line and implement event handlers in OEvents.ogs
    Note: More than one event handler file may exist in Origin.ini and the name is not restricted to OEvents.OGS.
  4. Close Origin and restart a new Origin session to check whether the history panel of Command Window is clean.

Origin C functions can be run from other sections of OEvents.OGS such as [BeforeOpenDoc]. View the Compiling, Linking and Loading page in Origin C Programming Guide for an example.

Please note that If you need to call Origin C functions from your custom script associated with events, you need to ensure that the Origin C file is compiled and the functions are available for script access. See Loading and Compiling Origin C Functions for details.