22.214.171.124 Loading and Compiling Origin C Functions
Loading and Compiling Origin C Function or Workspace
Before you call your Origin C function from Origin, your function must be compiled and linked in the current Origin session.
To programmatically compile and link a source file, or to programmatically build a workspace from a LabTalk script use the run.loadOC method of the LabTalk run object.
err = run.LoadOC("myFile",[option]);
Use option to scan the .h files in the OC file being loaded, and all other dependent OC files are also loaded automatically:
// Load and compile Origin C function in the file iw_filter.c
// with the option=16, so to also load all dependent Orign C
// files by scanning for .h files included in iw_filter.c
if(run.LoadOC(OriginLab\iw_filter.c, 16) != 0)
type "Failed to load iw_filter.c!";
Now, open Code Builder by menu View: Code Builder, and in the Workspace panel (if not see this panel, open by View: Workspace menu item in Code Builder) of Code Builder, you can see the iw_filter.c file is under the Temporary folder.
Adding Origin C Source Files to System Folder
Once a file has been opened in Code Builder, one can simply drag and drop the file to the System branch of the Code Builder workspace. This will then ensure that the file will be loaded and compiled in each new Origin session. For more details, please refer to Code Builder documentation.
You can programmatically add a source file to the system folder so that it will be available anytime Origin is run.
run.addOC(C:\Program Files\Originlab\Source Code\MyFunctions.c);
This can be useful when distributing tools to users or making permanently available functions that have been designed to work with Set Column Values.
Adding Origin C Files to Project (OPJ)
Origin C files (or files with any extension/type) can also be appended to the Origin project (OPJ) file itself. The file will then be saved with the OPJ and extracted when the project is opened. In case of Origin C files, the file is then also compiled and linked, and functions within the file are available for access. To append a file to the project, simply drag and drop the file to the Project branch of Code Builder or right-click on Project branch and add the file. For more details, please refer to Code Builder documentation.