1.4.5 Distributing Origin C Code


Distributing Source 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.

Distributing Applications

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). 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.

  1. 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.
    void OnButtonClick()          
    {
    	Worksheet wks = Project.ActiveLayer();
    	
    	DataRange dr;
    	dr.Add(wks, 0, "X");
    	dr.Add(wks, 1, "Y");
    	
    	GraphPage gp;
    	gp.Create();
    	GraphLayer gl = gp.Layers(0);
    	
    	int nn = gl.AddPlot(dr);
    	gl.Rescale();
    }
  2. 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.
    [Main]
    	if(0 == Run.LoadOC(%Y\OriginC\MyButton.c))
    	{
    		OnButtonClick;
    	}
  3. 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.
  4. In the Customize Tool dialog, select MyButton item from Groups list, and click to choose the MyButton.png 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.
  5. Click Export to open the Export Button Group dialog, then click Add File and choose the above MyButton.c file.
    ExportButtonGroup.png
  6. Click Export button, then in the Save As dialog click Save to save the MyButton.OPX file to the specified folder.
  7. Choose menu Tools: Package Manager, and in the dialog that opens, choose File: Open to open the MyButton.OPX file. Put the script
    Run.LoadOC(%Y\OriginC\MyButton.c);
    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.