22.214.171.124 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
- If Origin is running, exit the program.
- Start a fresh page in a text editor (e.g. Notepad) and enter the following information:
@global = 1;
// This function calculates the cube root of a number
function double dCubeRoot(double dVal)
if(dVal<0) xVal = -exp(ln(-dVal)/3);
else xVal = exp(ln(dVal)/3);
@global = 0;
- Name and save the file to your the User Files Folder (UFF), using an .OGS file extension (e.g. myLTFuncs.ogs).
- Browse to your Origin.ini file in your UFF and open this file in your text editor.
- Locate the [Startup] section of the file and add the name of the .OGS file you just created using the following form:
... where N is 1,2,3,etc.
- Save your changes to Origin.ini.
- 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.
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.)
- 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.
- 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";
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.
- Close Origin and restart a new Origin session to check whether the history panel of Command Window is clean.