1 Orglab

Introduction

OrgLab is a freely distributable COM library for directly creating Origin project files (OPJ or OPJU). Custom applications use COM technology to communicate with OrgLab.

While OrgLab's COM interface appears to be the same as Origin's COM interface, it is important to understand that Orglab is not a replacement for Origin and not all of OrgLab's COM methods and properties will behave the same as those of Origin.

Additionally, OrgLab and Origin/OriginPro can be installed and running on the same computer because OrgLab is not dependent upon Origin/OriginPro when creating project files.

Finally, by downloading, using, and/or distributing OrgLab, the user agrees to the terms of the OrgLab EULA. Per the Orglab EULA:

"...Licensee may not resell, rent, lease, distribute or otherwise use the Developer Software in any way that would compete with OriginLab's Origin and OriginPro products."

Read the Orglab End-User License Agreement for full details.

Download

Download the latest OrgLab release (OrgLab9) from OrgLab Download.

OrgLab9 is 64-bit only and is distributed in a ZIP file containing 4 files:

  • OrgLab9.dll
  • orglab9.tlb
  • OrglabEULA.txt
  • ReadMe.txt

When distributing OrgLab, these files must be included: OrgLab9.dll, orglab9.tlb, and OrglabEULA.txt.

Installation

Before installing OrgLab, you must install the 64-bit (x64) Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 from this page: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads. Note: if Origin 2020 or later is installed in the same computer, the redistributable should already be installed.

To install OrgLab itself:

  1. Copy OrgLab9.dll, orglab9.tlb, and OrglabEULA.txt files to the desired destination folder.
  2. Run Windows Command Prompt ('cmd.exe') as Administrator.
  3. cd to the destination folder.
  4. Run this command from the Command Prompt: regsvr32 "orglab9.dll"
  5. A message box will appear letting you know the registration has succeeded.

Upgrading from OrgLab8

If you are upgrading from OrgLab8 to OrgLab9, you will have to modify your custom application and recompile it.

For C++ projects, the following change must be made.

Change this:

CLSIDFromProgID(L"OrgLab8.Application", &clsid);

To this:

CLSIDFromProgID(L"OrgLab9.Application", &clsid);

For C# and Visual Basic, the following change must be made.

Change the OrgLab Type Library Reference from this:

OriginLab Orglab8 Type Library;

To this:

OriginLab Type Library

Note that version information is missing from the Type Library Reference. This is due to a defect in type library generation but it does not impact performance.

Examples

The following examples demonstrate uses for OrgLab.

For more examples of communicating with OrgLab, please refer to the Origin COM Examples.

A popular example demonstrates how to read and write an OGW file: Accessing OGW

C#

EX1

// Be sure to add 'OriginLab Type Library` (which is OrgLab9) to your project's References
using Origin;

static void Main(string[] args)
{
	object Default = System.Type.Missing;

	Origin.Application originApp = new Origin.Application();

	originApp.NewProject();

	string strPageName = originApp.CreatePage
                     ((int)Origin.PAGETYPES.OPT_WORKSHEET, Default, "", 2);

	originApp.Save("C:\\CreatedProject1.opj");   // Save as old opj format
        originApp.Save("C:\\CreatedProject2.opju");  // Save as new opju format

	originApp.Exit();
}

EX2

// Create, Save, and Load Project
static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
 
    // Create and Save a Project with Only One Workbook
    oApp.NewProject();
    oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\OneWorkbook.opj");
 
    // Load a Project, Add a Workbook, and Save As Another Project
    oApp.NewProject();
    oApp.Load(System.IO.Directory.GetCurrentDirectory() + @"\OneWorkbook.opj");
    oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\TwoWorkbooks.opj");
 
    oApp.Exit();
}

EX3

// Create Worksheet and Send Data to It
static void Main(string[] args)
{
    // New Origin Project
    Origin.Application oApp = new Origin.Application();
    oApp.NewProject();
 
    // Two Columns of Data: y = sin(x), x in [0, 10.0]
    double[,] data = new double[101, 2];
    for (int i = 0; i <= 100; i++)
    {
        data[i, 0] = i / 10.0;
        data[i, 1] = Math.Sin(data[i, 0]);
    }
 
    // Create Worksheet
    string wpname;
    wpname = oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    Origin.Worksheet wks = oApp.FindWorksheet(wpname);
 
    // Send Data to Worksheet
    wks.SetData(data);
 
    // Set First Column as X
    wks.Columns[0].Type = Origin.COLTYPES.COLTYPE_X;
 
    //Save As .OPJ File and Exit
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\SendDataToNewWorksheet.opj");
    oApp.Exit();
}

EX4

// Create Matrix Page and Send Data to It
static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
    oApp.NewProject();
    double[,] data = new double[100, 100];
    for (int i = 0; i < 100; i++)
        for (int j = 0; j < 100; j++)
            data[i, j] = i * j;
 
    // Create Matrix Page
    string mpname = oApp.CreatePage((int)Origin.PAGETYPES.OPT_MATRIX);
    Origin.MatrixPage mp = oApp.FindMatrixSheet(mpname).Parent;
 
    // Number of Matrix Sheets: 3
    while (mp.Layers.Count < 3)
        mp.Layers.Add();
 
    foreach (Origin.MatrixSheet msht in mp.Layers)
    {
        msht.Name = "MSheet" + msht.Index.ToString();
 
        // Number of Matrix Object per Matrix Sheet: 4
        msht.Mats = 4;
 
        // Dimension: 100x100
        msht.Cols = 100;
        msht.Rows = 100;
 
        // Send Data to Matrix Object
        foreach (Origin.MatrixObject mo in msht.MatrixObjects)
            mo.SetData(data);
    }
 
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\MatrixPage.opj");
    oApp.Exit();
}

EX5

// Get Data From Worksheet, Column, and Matrix Object

// Suppose that there are at least two sheets in Book1,
// and at least one matrix object in [MBook1]MSheet1!.
// Assume there is no graph page with data plot existing 
static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
 
    // Make sure no graph page with data plot exists before loading opj
    oApp.Load(System.IO.Directory.GetCurrentDirectory() + @"\GetDataFromOPJ.opj");
     
    // Current Layer of Book1 or MBook1
    Origin.Worksheet wks = oApp.FindWorksheet("Book1");
    Origin.MatrixSheet msht = oApp.FindMatrixSheet("MBook1");
     
    // Data in [Book1]1
    object wksData = wks.Parent.Layers[0].GetData(0, 0, -1, -1, Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC);
     
    // Data in [Book1]2!1
    object colData = wks.Parent.Layers[1].Columns[0].GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_STR, 0, -1);
     
    // Data in [MBook1]1!1
    object moData = msht.MatrixObjects[0].GetData(0, 0, -1, -1, Origin.ARRAYDATAFORMAT.ARRAY2D_NUMERIC);
 
    oApp.Exit();
}

EX6

// Custom Column Label Row
static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
    oApp.NewProject();
 
    // 1. Create Worksheet
    Origin.Worksheet wks;
    string wksName = oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    wks = oApp.FindWorksheet(wksName);
    wks.Cols = 1;
    wks.Rows = 32;
 
    // 2. Show Label Rows: 'Long Name', 'Units', 'Comments', 'Sample Rate', and 2 'Parameters'
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_LONG_NAME, true);
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_UNIT, true);
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_COMMENT, true);
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_SAMPLE_RATE, true);
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_PARAM, true);
    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_PARAM + 1, true);
 
    // 3. Set Label Rows
    wks.Columns[0].LongName = "Long Name";
    wks.Columns[0].Units = "Units";
    wks.Columns[0].Comments = "Comments";
    wks.Columns[0].Parameter[0] = "Parameter 1";
    wks.Columns[0].Parameter[1] = "Parameter 2";
 
    // 4. Even Sampling
    wks.Columns[0].SetEvenSampling(0.0, 0.1);
 
    // 5. Data
    double[] data = new double[32];
    for (int i = 0; i < 32; i++)
        data[i] = i / 5.0;
    wks.Columns[0].SetData(data);
 
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\ColumLabelRows.opj");
    oApp.Exit();
}

EX7

// Custom Column Display Format
static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
    oApp.NewProject();
 
    double[,] data = new double[32, 3];
    for (int i = 0; i < 32; i++)
    {
        data[i, 0] = i / 10.0;
        data[i, 1] = Math.Cos(i / 10.0);
        data[i, 2] = Math.Sin(i / 10.0);
    }
 
    string wpname = oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    Origin.Worksheet wks = oApp.FindWorksheet(wpname);
    wks.SetData(data);
 
    // Display: Scientific 1E3
    wks.Columns[0].DisplayFormat = 1;
 
    // Digits: Set Decimal Places = 6
    wks.Columns[1].DigitMode = Origin.DIGITMOD.DIGITMODE_DECIMAL_DIGITS;
    wks.Columns[1].Digits = 6;
 
    // Digits: Significant Digits = 6
    wks.Columns[2].DigitMode = Origin.DIGITMOD.DIGITMODE_SIGNIFICANT_DIGITS;
    wks.Columns[2].Digits = 6;
 
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\NumericFormat.opj");
    oApp.Exit();
}

EX8

// Meta Data in Organizer of Workbook
using System.Xml;

static void Main(string[] args)
{
    Origin.Application oApp = new Origin.Application();
    oApp.NewProject();
 
    // Meta Data
    XmlDocument xmlDoc = new XmlDocument();
    XmlNode Node;
    XmlElement topXML, Element;
    topXML = xmlDoc.CreateElement("data");
    Node = xmlDoc.AppendChild(topXML);
    Node = Node.AppendChild(xmlDoc.CreateElement("Instrument"));
    Element = xmlDoc.CreateElement("SerialNumber");
    Element.InnerText = "EQR-23456";
    Node = Node.AppendChild(Element);
    Element = xmlDoc.CreateElement("UsageCount");
    Element.InnerText = "2345";
    Node = Node.ParentNode.AppendChild(Element);
 
    string strXML = topXML.OuterXml;
 
    // Meta Data in a Workbook
    string wpname = oApp.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET);
    Origin.Worksheet wks = oApp.FindWorksheet(wpname);
    wks.SetMetaData(strXML, "MetaData", true);
 
    oApp.Save(System.IO.Directory.GetCurrentDirectory() + @"\MetaData.opj");
    oApp.Exit();
}