AnsweredAssumed Answered

How do I retrieve attributes from multiple elements at a time?

Question asked by karmstrong on Aug 11, 2016
Latest reply on Aug 12, 2016 by karmstrong

This has been a particularly frustrating task - I've read :

https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/203b8cca-678e-4009-846e-4df75bc65a32.htm

 

And maybe I'm missing something simple.

 

I want to read from a PI AF database, find all elements relating to a template, then find the attributes of that template, then find the values of each attribute.

I'm going to be serializing the elements, their attributes, and their matching values to JSON and transmitting them.

 

I've stared with this:

                     AFElementTemplate afTemplate = _afDB.ElementTemplates[_tankConfig.TankTemplate];


                    // Lo
                     AFElementTemplate afTemplate = _afDB.ElementTemplates[_tankConfig.TankTemplate];


                    // Load all elements based on tank template into a named collection list.
                    AFNamedCollection<AFElement> afElements =
                        AFElement.FindElementsByTemplate(_afDB, null, afTemplate, false, AFSortField.Name, AFSortOrder.Ascending, int.MaxValue);


                    //AFAttributeList attributes = new AFAttributeList();
                    AFAttributeList attributes = new AFAttributeList();


                    foreach (AFElement element in afElements)
                    {
                        attributes.Add(element.Attributes);
                        //AFAttributeList attributes = new AFAttributeList();
                    }
                    AFValues values = attributes.GetValue(); // Returns ALL values of EACH AFAttribute in the list.
ad all elements based on tank template into a named collection list.
                    AFNamedCollection<AFElement> afElements =

 

Now I know that I need to populate the attributes AFAttributeList with attributes, but I don't know how to do this without using a for loop to add each attribute from each element individually. Furthermore, I can only initialize an AttributeList with an element. Do I need a different attribute list for every case, or should I be using another data structure to hold all of this information?

 

What is the most conventional means of doing this?

Outcomes