This tutorial will show you how to share code with other users by distributing OPX files. In this example, only Origin C files are distributed. However, please note that OPX distribution can include any file types including (but not limited to) project files, templates and toolbars.
The following procedure will show you how to distribute your Origin C code to other Origin users. In this example, we will be packaging an Origin-C function in a file (MyCode.c) in a folder (MyFunctions) under the User Files Folder (UFF).
The Source Path for your files should be available on any computer your OPX is targeted for. The easiest way to do this is to make a subfolder of the Origin UFF. Any of the files and folders of the UFF can then be added to your OPX for distribution. So, create a subfolder named MyFunctions under the UFF.
Copy all the files to be packaged to the subfolder created in the last step. Here there is only a C file (MyCode.c). The function in this file is shown below.
void get_data_from_wks() { Worksheet wks = Project.ActiveLayer(); if( !wks ) { out_str("Please keep a worksheet active with data"); return; } // The following settings to set range as whole worksheet, // index offset is 0, -1 means last row/column. // Change r1, c1, r2, c2 to specify worksheet sub range, // for example, r1 = 0, c1 = 1, r2 = -1, c2 = 2 to // select all rows from column 2 to column 3. int r1 = 0; // first row int c1 = 0; // first column int r2 = -1; // last row int c2 = -1; // last column //construct a data range object from worksheet all data DataRange dr; dr.Add("X", wks, r1, c1, r2, c2); // get data from worksheet to vector by column one by one matrix mData; dr.GetData(mData); // get all data to matrix for(int nColIndex = 0; nColIndex < mData.GetNumCols(); nColIndex++) { vector vOneCol; mData.GetColumn(vOneCol, nColIndex); double min, max; vOneCol.GetMinMax(min, max); printf("Maximum value of %d column = %f\n", nColIndex+1, max); } }
Open the Package Manager by selecting Tools: Package Manager.... Then fill in the dialog as the following image shows.
run.addoc(%YMyFunctions\MyCode.c);
Select the File: Save menu of this Package Manager dialog. In the pop-up Save As dialog, enter a name (in this example, can be MyCode) for this package, and then save it as an OPX file.
Send the saved OPX file to other users. The user who gets this package can drag and drop the OPX onto Origin to install it, and then the functions in the C file are available.
get_data_from_wks;