2.34.13 SetMetaData


Description

Syntax

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

Parameters

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

Return

A boolean value with true indicating set meta data successfully and false indicating it is failed.

Remark

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

Examples

VBA

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 SetMetaData() 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
 
    'Set MetaData
    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
    
    'Get MetaData, and show them in Excel cell
    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

VB

    Sub SetMetaData()
        Dim app As Origin.ApplicationSI
        Dim mtxPage As Origin.MatrixPage
        Dim mtxSheet As Origin.MatrixSheet
        Dim strXML As String
        Dim bRet As Boolean
        Dim tree As Xml.XmlDocument
        Dim treeNodeTop As Xml.XmlElement
        Dim treeNode As Xml.XmlElement
        tree = New Xml.XmlDocument
        'Set XML String, which has one branch and two nodes.
        treeNodeTop = tree.AppendChild(tree.CreateElement("OriginStorage"))
        treeNode = treeNodeTop.AppendChild(tree.CreateElement("Instrument"))
        treeNode = treeNode.AppendChild(tree.CreateElement("SerialNumber"))
        treeNode.InnerText = "EQR-23456"
        treeNode = treeNode.ParentNode
        treeNode = treeNode.AppendChild(tree.CreateElement("UsageCount"))
        treeNode.InnerText = "2345"

        strXML = treeNodeTop.OuterXml.ToString()

        app = New Origin.ApplicationSI
        mtxSheet = app.FindMatrixSheet("")   'Get active MatrixSheet, if not exist, exit Sub
        If mtxSheet Is Nothing Then
            Exit Sub
        End If
        mtxPage = mtxSheet.Parent   'Get active MatrixPage

        'Set MetaData
        bRet = mtxSheet.MatrixObjects(0).SetMetaData(strXML, "UserColInfo", True)   'Set XML to MatrixObject
        bRet = mtxSheet.SetMetaData(strXML, "UserSheetInfo", True)     'Set XML to MatrixSheet
        bRet = mtxPage.SetMetaData(strXML, "UserBookInfo", True)     'Set XML to MatrixPage
        bRet = mtxPage.SetMetaData(strXML, "CustomTree", False)    'Set XML to MatrixPage. This will no longer be visible from book organizer, but can be accessed from Origin C program
    End Sub

C#

using Origin;
using System.Xml;
static void SetMetaData()
{
    //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

    //Set MetaData
    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

    //Get MetaData, and output them to console window
    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");

}

VC++

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

static void SetMetaData()
{
	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 )
	{
		pwks->Activate();
		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
		pOrigin->Save(pOrigin->Path(Origin::APPPATH_USER) + "SetMetaData.opj" ); //save project for check whether it is successfully set

	}
	return;
}

Version Information

8.0SR2

See Also

GetMetaData