3.7.5.54 Run(object)Run-obj
LabTalk Object Type:
- Utility
The run object executes script from a script file. Origin tools use the run.section() method to execute sections of the appropriate *.OGS file.
Properties:
Property
|
Access
|
Description
|
run.automate
|
--
|
Internal use only. Not implemented in Origin.
|
run.ocworkspace
|
--
|
Internal use only. Not implemented in Origin.
|
Methods:
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 err return value:
- If err = 0, indicates success. Either myFile is already loaded in the current workspace or it is loaded from a *.C file and compiled and linked successfully.
- If err = 1, myFile was not found.
- If err = 2, myFile was found and loaded into the current workspace, but the compiling or linking failed.
The myFile argument:
- The myFile can be either a workspace file (*.OCW) or a source file (*.C, *.CPP). If myFile is a workspace file, Origin checks each source file in the workspace file to see whether or not it is already loaded. If myFile is a source file, Origin checks to see if it is already loaded.
- In either case, if a source file is not already loaded then Origin adds it to the Temporary folder in the Code Builder workspace. When Origin is finished checking, it builds the Code Builder workspace. Files added to the Temporary folder of the Code Builder workspace are removed from the workspace when you close Code Builder or when you open a new or existing workspace file. Files can also be programmatically removed from the Temporary folder using the LabTalk run -cr <filename> command.
- You must surround myFile with quotation marks ("myFile").
- If no file extension is included, myFile is assumed to be a source file (*.C).
- If myFile has a full path, then it is used as is. If a path is not specified, Origin assumes that myFile is located in the \OriginC subfolder.
- The file name myFile supports wildcards.
The option argument:
Note: Options 1,2,4 and 8 are for internal use and are not recommended.
- 1 - Add file to Workspace User folder, but not Temporary Folder.
- 2 - Loads, compiles, and links the file that is not already compiled and linked; otherwise does nothing.
- 4 - Disable adding internal.c to the Workspace (Otherwise added by default).
- 8 - Disable linking. Method of suspending linking until all files are loaded (See example).
- 16 - Load all dependent Origin C files by scanning for .h files in the OC file being loaded.
- 2048 - Add file to the AutoLoad folder.
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.
- option = 0 (default), execute Python command
- In this case, arg should be the Python statement(s) and this is equivalent to the run -py command.
- option = 1, evaluate Python expression
- In this case, arg should be the Python expression and this is equivalent to the run -pye command.
- option = 2, execute Python file
- In this case, arg should be the path and name of the .py file and this is equivalent to the run -pyf command.
- option = 16, suppress output
- In this case, nothing will be output after execution
- option = 32 or 33, set the file path
- In this case, the path will be used when run.python(PythonFile, 2) when the full path of the file is not specified.
|
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:
run.section( ,Init);
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 Functions:
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.
Run Python:
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);
Examples:
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;
See Also:
LabTalk:OGSFileName (command), LabTalk:OGSFileName.SectionName (command)
|