AnsweredAssumed Answered

PI AF SDK Code Deletes Attributes After Assigning Element to Template

Question asked by Dillon.Brennan on Jan 27, 2020
Latest reply on Jan 27, 2020 by Dillon.Brennan

My C# PI AF SDK code deletes all attributes (A) in existing elements (B) when said elements (B) are assigned to newly created element templates (C).  These newly created element templates (C) already have empty attribute templates (D) with same names, which match attributes (A).


In the past, when performing this technique manually in the GUI for PI AF, there were no issues.  We've created many element templates with analyses and event frames that work just fine (excluding network issues).


Note, I understand this is not the optimal way to create element templates.  However, have created element templates in this manner because we are migrating from an existing equipment monitoring software (GE SmartSignal) to PI AF. 


Our "elements" have already been built out with applicable "attributes" in our existing software.  To avoid double work we made a python script that converted our SmartSignal assets to PI AF elements.


Here's the block of code I'm working with:


//Assign the element we are assigning to a template to "path" (string)-- where "result" is an AFElement

string path = result.GetPath();


//Get name of desired element template using a VLookup in Excel-- where xlRange is the active range in the worksheet

string elemLookVal = xlApp.WorksheetFunction.VLookup(path,xlRange.Columns["A:B"],2);


//Search the AF Database, "DB", by name and create an AFElementTemplate object called "elemTempary"

AFNamedCollectionList<AFElementTemplate> elemTempary = AFElementTemplate.FindElementTemplates(DB, elemLookVal, AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 1000);


//Assign newly found element template to the element of concern

result.Template = elemTempary[0];



After refreshing AF, the element has all of its attributes deleted and it's not even assigned to the element template.  Any advice/help is appreciated.