2.34.12 GetMetaData



VB: Function GetMetaData(Name As ByVal String, bVisibleToUser As ByVal Boolean ) As String
C++: LPCSTR GetMetaData(LPCSTR Name, bool bVisibleToUser )
C#: string GetMetaData(string Name, bool bVisibleToUser )


Name of the XML
If it is false, XML will no longer be visible from book organizer, but can be accessed from Origin C program


A string XML


Supported for Column, Worksheet, WorkbookPage, Layer, MatrixObject, MatrixLayer and GraphPage



Connect to the running Origin. Create an XML string, and set it to Column, Worksheet and Workbook. You can see the result in Origin. Then, get them back from Origin, and output it to Excel sheet.

'Add Reference to Microsoft XML v2.6 or later
Function GetMetaData() As String
    Dim app As Origin.ApplicationSI
    Dim WkBk As Origin.WorksheetPage
    Dim Wks As Origin.Worksheet
    Dim strXML As String
    Dim bRet As Boolean
    Dim tree As MSXML2.DOMDocument
    Dim treeNodeTop As MSXML2.IXMLDOMElement
    Dim treeNode As MSXML2.IXMLDOMElement
    Set tree = New MSXML2.DOMDocument
    'Set XML String, which has one branch and two nodes.
    Set treeNodeTop = tree.appendChild(tree.createElement("OriginStorage"))
    Set treeNode = treeNodeTop.appendChild(tree.createElement("Instrument"))
    Set treeNode = treeNode.appendChild(tree.createElement("SerialNumber"))
    treeNode.Text = "EQR-23456"
    Set treeNode = treeNode.parentNode
    Set treeNode = treeNode.appendChild(tree.createElement("UsageCount"))
    treeNode.Text = "2345"
    strXML = treeNodeTop.XML
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")   'Set Wks as the active Worksheet
    Set WkBk = Wks.Parent   'Set WkBk as the active Workbook
    bRet = Wks.Columns(0).SetMetaData(strXML, "UserColInfo", True)   'Set XML to Column
    bRet = Wks.SetMetaData(strXML, "UserSheetInfo", True)     'Set XML to Worksheet
    bRet = WkBk.SetMetaData(strXML, "UserBookInfo", True)     'Set XML to Workbook
    bRet = WkBk.SetMetaData(strXML, "CustomTree", False)    'Set XML to Workbook. This will no longer be visible from book organizer, but can be accessed from Origin C program
    Range("A1") = Wks.Columns(0).GetMetaData("UserColInfo", True)
    Range("A2") = Wks.GetMetaData("UserSheetInfo", True)
    Range("A3") = WkBk.GetMetaData("UserBookInfo", True)
    Range("A4") = WkBk.GetMetaData("CustomTree", False)
End Function


using Origin;
using System.Xml;
static void GetMetaData()
    //Set XML String, which has two branch and some nodes.
    XmlDocument xmlDoc = new XmlDocument();
    XmlNode Node;
    XmlElement topXML;
    XmlElement 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;

    Origin.ApplicationSI app = new Origin.ApplicationSI();     //Connect to the running Origin
    Worksheet wks = app.FindWorksheet("");     //Set wks as the active Worksheet
    WorksheetPage wkbk = (WorksheetPage)wks.Parent;     //Set wkbk as the active Workbook

    wks.Columns[0].SetMetaData(strXML, "UserColInfo", true);     //Set XML to Column
    wks.SetMetaData(strXML, "UserSheetInfo", true);     //Set XML to Worksheet
    wkbk.SetMetaData(strXML, "UserBookInfo", true);     //Set XML to Workbook
    wkbk.SetMetaData(strXML, "CustomTree", false);     //Set XML to Workbook. This will no longer be visible from book organizer, but can be accessed from Origin C program

    Console.WriteLine(wks.Columns[0].GetMetaData("UserColInfo", true) + "\n"
                    + wks.GetMetaData("UserSheetInfo", true) + "\n"
                    + wkbk.GetMetaData("UserBookInfo", true) + "\n"
                    + wkbk.GetMetaData("CustomTree", false));

    //Save the project
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "SetMetaData.opj");



The code will launch a new instance of Origin. After updating meta data, it will get it back and show in a messagebox.

#import "Origin8.tlb" rename_namespace("Origin")
using namespace Origin;
using namespace System::Xml;

static void  GetMetaData()
	XmlDocument xmlDoc;
	XmlElement^ xmlEleTop = xmlDoc.CreateElement("DAQ");
	//make the data branch Read Only with blue text, 0=disable, 1 = enable, 2 = read-only blue text, 3=read-only normal text
	xmlEleTop->SetAttribute("Enable", "2");

	XmlNode^ xmlNode = xmlDoc.AppendChild(xmlEleTop);
	xmlNode = xmlNode->AppendChild(xmlDoc.CreateElement("Data"));

	XmlNode^ xmlEle = xmlDoc.CreateElement("StartTime");
	xmlEle->InnerText = "2008-12-25 15:35:36.222";
	xmlNode = xmlNode->AppendChild(xmlEle);

	xmlEle = xmlDoc.CreateElement("StopTime");
	xmlEle->InnerText = "2008-12-25 15:40:40.125";
	xmlNode = xmlNode->ParentNode->AppendChild(xmlEle);

	xmlEle = xmlDoc.CreateElement("Operator");
	xmlEle->InnerText = "Sophy Huang";
	xmlNode = xmlNode->ParentNode->AppendChild(xmlEle);
	xmlNode = xmlNode->ParentNode->ParentNode->AppendChild(xmlDoc.CreateElement("Instrument"));
	//make the Instrument branch Read Only with normal text
	xmlEleTop->SetAttribute("Enable", "3");

	xmlEle = xmlDoc.CreateElement("SerialNumber");
	xmlEle->InnerText = "EQR-23456";
	xmlNode = xmlNode->AppendChild(xmlEle);
	xmlEle = xmlDoc.CreateElement("UsageCount");
	xmlEle->InnerText = "2345";
	xmlNode = xmlNode->ParentNode->AppendChild(xmlEle);

	CString str = xmlEleTop->OuterXml;
	_bstr_t strXML = str.GetString();
	Origin::IOApplicationPtr pOrigin;
	pOrigin.CreateInstance(__uuidof(ApplicationSI)); //connect to running Origin instance

	pOrigin->CreatePage( PAGE_TYPE_WKS, "CustomerBook", "w", PAGE_VISIBLE);
	Origin::WorksheetPagePtr pWksPage = pOrigin->GetActivePage();
	Origin::WorksheetPtr pwks = pWksPage->GetLayers()->Add("UserData");
	if ( pwks )
		Origin::ColumnPtr pCol = pwks->GetColumns()->Add("MyVC++");

		pCol->SetMetaData(strXML, "UserColInfo", true);//set XML to Column
		pwks->SetMetaData(strXML, "UserSheetInfo", true); //set XML to worksheet
		pWksPage->SetMetaData(strXML, "UserBookInfo", true); //set XML to workbook
		pWksPage->SetMetaData(strXML, "CustomTree", false); //set XML to workbook, this will no longer be visible from book organizer but can be accessed by OC code

		_bstr_t strOutput = pCol->GetMetaData("UserColInfo", true) + "\n"
                    + pwks->GetMetaData("UserSheetInfo", true) + "\n"
                    + pWksPage->GetMetaData("UserBookInfo", true) + "\n"
                    + pWksPage->GetMetaData("CustomTree", false);

		MessageBox(NULL, strOutput, L"MetaData", MB_OK);
		pOrigin->Save(pOrigin->Path(Origin::APPPATH_USER) + "SetMetaData.opj" ); //save project for check whether it is successfully set


Version Information


See Also