PI System Explorer allows user to copy an element and then use "paste" to paste a new element with same children elements.
How can I do this programmatically using the AF SDK?
Copy/Paste is implemented in PSE using the ExportXml/ImportXml methods of the PISystem object in the AFSDK. You will want to use the PasteOperation PIExportMode.
I can't find a simple AFSDK method to achieve the copy and paste functionality similar to PSE. Basically, you will have to create new elements and copy the properties/attributes from the copied element to the new element, changing its name when necessary. You will then have to add the new element to the database. A similar procedure exists for the associated child elements. Before going down this path, may I ask what your use case is? This seems to me a perfect opportunity to use element templates instead. We will be able to further assist you when we have some additional information.
EDIT: Thanks David for the comment! Wenpeng, please refer to David's suggestion below. If you need specific examples, let use know and we will be happy to provide them.
Hi Daphne Ng, David Hearn
Thank you very much, appreciate your help! As you suggested, I have figured out how to do that using PISystem.ExportXml and PISystem.ImportXML.
Here are example code:
AFElement DVP = GetElement("DVP", null, AFDB); //Get AFElement, whose name is "DVP", from AF database. "GetElement(...)" is a function defined by myself to get an Element by name from a AF database and Parent Element.
AFElement Acca = GetElement("Acca", DVP, AFDB); //Get one of "DVP"'s child: "Acca"
string XML = AFDB.PISystem.ExportXml(Acca, PIExportMode.Flat); //Export Acca as a XML string
DVP.PISystem.ImportXml(DVP, PIImportMode.PasteOperation, XML); //Import Acca to DVP (paste)
After doing this, "Acca" is pasted to DVP and the new "Acca" is renamed to "Acca1".
Retrieving data ...