4.45 FAQ-656 How to run Origin from command line?
Last Update: 9/9/2016
One method of program automation is to execute a program and pass arguments on the command line. The program should have been written to read these arguments and process them accordingly.
Here we will present one example of how to automate Origin using the command line. Other methods are possible and should be evaluated based on your needs.
The options that can be specified on Origin's command line include (but are not limited to):
- Specifying a project name or a window name. A path may be included and the file extension must be specified:
<Origin.EXE path and name> "D:\My Documents\MyGraph.OGG"
- Specifying a Workbook Template to load on startup. The file must be in your User Files Folder and must have an OTW extension. You do not specify a path and the OTW extension is not needed. As of 9/9/2016, the template name is limited to 8 characters, excluding the file extension.
<Origin.EXE path and name> -tw MyWKB
- Specifying a configuration file. The file must be in the User Files Folder and must have a CNF extension. You do not specify a path and the CNF extension is not needed.
<Origin.EXE path and name> -a MyCNF
- Configuration files can include any LabTalk command, but typically contain menu commands and macro definitions. Additional command line options control initialization files and menu levels. While also quite useful, using these files is more complex than the example presented here. For more information, see Working with Files.
There is no method for Origin to read what command line arguments were passed so the automation must be controlled by the file that is opened. This file may define a macro that Origin knows to execute under specific circumstances or it may contain an object that has script which executes for certain events.
Here is a summary of the process for each method:
The AUTOEXEC macro (if defined) executes when Origin starts and when selecting File : New or File : Close from the menu. By passing a configuration file which defines AUTOEXEC, Origin can be made to execute any scripts you want. If your script does not close Origin or redefine AUTOEXEC, then a user may execute these scripts again by selecting File: New: Project or File: Close.
By opening a project file, child window or Template file which contains a Graphic Object, the Graphic Object can contain script which runs on a specific event. Typically, this script is set to run on the "Window Create" event, but more complex interactions are possible.
Create a text file named COMMAND.CNF and save it to your User Files Folder. The text file contents should be:
string bkPath$ = system.path.program$ + "Samples\Curve Fitting\Linear Regression.OGW";
doc -o %(bkPath$);
string dataPath$=system.path.program$ + "Samples\Curve Fitting\Sensor01.dat";
sec -p 3;
type -b Automation complete.; // Remove this line for complete automation
Using Windows Run, a command prompt beginning with START, or your application's call to a command shell, you can start Origin and pass the above file as an argument. For example, run below command:
<Origin.EXE path and name> -r run.section(command.cnf, Main)
The example loads an Origin analysis template, imports a sample data file and saves the resulting OPJ to <UFF path>Sensor01.opj (note that when no path is passed to run.section, the User Files Folder is assumed). A message box is displayed to the script has run to completion. When you click the OK button, Origin will close.
Keywords:Command Window, LabTalk, Origin Startup