LabTalk Object Type:
The run object executes script from a script file. Origin tools use the run.section() method to execute sections of the appropriate *.OGS file.
Property | Access | Description |
---|---|---|
run.automate | -- | Internal use only. Not implemented in Origin. |
run.ocworkspace | -- | Internal use only. Not implemented in Origin. |
Method | Description |
---|---|
run.addOC(fileName) |
Add a file to the System folder of Code Builder's Origin C Workspace. After successfully adding the file compile and link it. |
run.dialog(OGOName[,DLLObject]) |
General mechanism for tool launching. OGOName is the tool OGO file name. DLLObject is the object (existing in an external DLL) that contains source values for the tool sub-objects. (For a full discussion of "source" and tool sub-objects, see the draw.set() method.) The run.dialog() method is equivalent to the following script: dotool -w OGOName; run.section(OGSName,INIT); DLLObject.reset(); draw.set(OGOName,DLLObject); (Where the OGSName is named the same as OGOName.) The run.dialog() method returns 0 if there is no error. It returns 1 if there is an error. |
run.file(fileName) |
Execute the specified LabTalk script file. This is the preferred mechanism for running older user-defined script files without sections (versus using the run command). If the file has an OGS extension, then the extension is optional. If the file is located in your User Files Folder then the path is optional otherwise you must specify the full path. |
run.LoadOC("myFile", [option]) |
Load and compile an Origin C function or workspace with optional bit arguments.
The myFile argument:
The option argument:
These are bit values and can be combined using the bit wise OR operator |. If option is not specified then zero is used. |
run.python(arg, [option]) Minimum Origin Version Required: 2015 SR0 |
Execute Python statement(s) or files or evaluate Python expression(s), the arg should be a string variable including the Python statement, or file name and path, or Python evaluation, depending on the option. You can view the examples in the Run Python section below for sample usage.
|
run.section(fileName,sectionName[,arg1 arg2 arg3 arg4 arg5]) |
Execute the named section of the specified LabTalk script file. You can specify a path in fileName. If no path is specified, Origin first looks in the location of the open project, then the user files path, then the path to the Origin application file. Script file sections are separated by [section names]. For example, [Graph]. This method can pass up to five arguments to a section. Arguments in the script can be referred to using the temporary string variables: %1, %2, %3, %4, and %5. Note: When filename is not included, the current running script file is assumed. For example:
executes a subroutine Sub1 which is included in the currently running script file. This is a useful way to make a modular structure within a script file. |
Origin C source file often has dependent C files. The following example shows how you can compile just the main file and automatically compile its dependents with option 16.
if(run.LoadOC(Originlab\AscImpOptions, 16) == 0) run -oc AscImportFDLOGFiles(%H);
If you opens this file (AscImpOptions), you will see it has includes like
#include "fu_utils.h" #include "Import_Utils.h"
option 16 will tell the Origin C compiler to scan the first 50 lines of code (after all comments stripped) to find such header include lines and then find corresponding C files in the same folder and add them to workspace as well. In this case, fu_utils.c and Import_Utils will be automatically loaded as well.
You may also notice that the Origin C function AscImportFDLOGFiles was called with a LabTalk command run -oc. This technique allows the reduction of Origin C based function names to be directly visible from LabTalk, so as to prevent accidental name collisions. You will need to use
#pragma labtalk(2)
in the Origin C file to indicate subsequent functions to be callable only via run -oc, while
#pragma labtalk(0)
is used to completely prevent Origin C functions to be visible from LabTalk.
The following examples show how to use the run.python() method. Note that you need to make sure the Script Execution is set to LabTalk in the Script Window in order to run these scripts.
This LabTalk script directly executes Python command print('Hello Origin'):
run.python("print('Hello Origin')"); // This will print "Hello Origin" in Script Window
This script evaluates Python expression 2 ** 4:
run.python(" 2 ** 4 ", 1); //this will print 16 in Script Window.
This script first sets the file path to be <Origin EXE folder>\Samples\Python, and then execute the ListMember.py file under it:
// Define a string for the file path string file_path$ = system.PATH.PROGRAM$ + "\Samples\Python\"; // Set path of the python file run.python("%(file_path$)", 32); // Run the .py file named as ListMember.py under the selected path run.python("ListMember.py", 2); // This .py file list all provided functions in PyOrigin module
This script suppress the output so nothing will be output after execution:
run.python("print('Hello World')", 16);
This script executes the script in the [LegendSmartPos] section of the standard.OGS file and move the Legend to a best position.
run.section(standard, legendsmartpos);
This script executes the script in the [SimpleFit] section of the LR.OGS file and performs a linear fit of the data in the current graph window.
run.section(LR,SimpleFit);
This script loads a sequence of files into the User Folder Workspace, deferring Linking to the end:
// 9 combines 1 (load to User Folder) and 8 (defer linking) err = run.loadoc(originlab\initcode.c,9); // OR the errors together err = err | run.loadoc(originlab\maincode.cpp,9); err = err | run.loadoc(originlab\supportcode.c,9); if( err == 0) run.loadoc(); // This triggers the linking else printf("Some error(s) occurred. Linking not done.\n");
This script loads a file selected by file dialog into the User Folder in Workspace:
fdlog.UseGroup(OriginC); fdlog.Open(A); %B = fdlog.Path$; string fname$ = %B%A; fname$=; err = run.loadoc(%(fname$),1); if(err == 0) type -a Successfully load;
LabTalk:OGSFileName (command), LabTalk:OGSFileName.SectionName (command)