1.4.5 Distributing Origin C Code
Distributing Source CodeDistributing CodeShare Code
Origin users can share Origin C source code with one another by distributing either the source files themselves (.C, .CPP, .OCZ) or preprocessed files (.OP).
If it is not necessary for others to see your application's source code, it is highly recommended that you distribute the encrypted Origin C source files (.OCZ) or preprocessed files (.OP) for version before Origin 2015 instead of the source files (.C or .CPP).
For encrypted OCZ files, users only need to drag and drop them into Code Builder in Origin to view and edit content. A prompt will show up to ask for the password when you try to open it for the first time but it will be only asked once in same Origin session.
See the File Types in the Create and Edit an Origin C File section for more information.
When an encrypted OCZ file is open in Origin session, since Origin 2016 SR0 user can choose to re-save the *.ocz file as not encrypted *.c or *.cpp by selecting menu File: Save As and choose a file type in Save as type drop-down list.
After creating an application, you can distribute it as a single package file to other Origin users.
Use Package Manager to package all the application files into a single package file (.OPX)Package Files. Note that when adding your application files into the package, be sure to add the preprocessed files (.OP) or the source files (.C or .CPP). It is not necessary to add both.
Users can install your application by dropping the package file directly into Origin.
The following is an example that shows how to package all the application files into one OPX file. The user can drop the package file into Origin to install, then click a button to run the source file.
- Prepare an Origin C source file. In Code Builder, choose menu File: New to create a new c file named MyButton.c, copy the following code to it and save it to the User File Folder\OriginC\ subfolder.
Worksheet wks = Project.ActiveLayer();
dr.Add(wks, 0, "X");
dr.Add(wks, 1, "Y");
GraphLayer gl = gp.Layers(0);
int nn = gl.AddPlot(dr);
- Create an OGS file named MyButton.ogs to load the Origin C source file and call function. Copy the following and save it to the User File Folder.
if(0 == Run.LoadOC(%Y\OriginC\MyButton.c))
In the Origin menu, choose View: Toolbars. In the Customize Toolbar dialog, choose the Button Groups tab, and click New button to open the Create Button Group dialog. Set MyButton as the Group Name, keep Number of Buttons as 1, choose the Userdef.bmp file from the User File Folder as Bitmap, and click the OK button. In the ensuing Save As dialog, click the Save button to save the MyButton.ini file to the default path.
- In the Customize Tool dialog, select MyButton item from Groups list, and click to choose the button from Buttons panel, then click Settings button from Button group to open a Button Settings dialog. Choose MyButton.ogs as the File Name, type "Main" in for Section Name, then make sure the following check-boxes are unchecked: Matrix, Excel, Graph, Layout and Excel. Click OK to close the dialog.
- Click Export to open the Export Button Group dialog, then click Add File and choose the above MyButton.c file.
- Click Export button, then in the Save As dialog click Save to save the MyButton.OPX file to the specified folder.
- Choose menu Tools: Package Manager, and in the dialog that opens, choose File: Open to open the MyButton.OPX file. Put the script
into LabTalk Script: After Installation in gird view to load the Origin C source file. This script will be run when you drop OPX into Origin to install this application.