AnsweredAssumed Answered

What is the most efficient way to get attribute values from multiple elements?

Question asked by Lhub01 on Apr 15, 2019
Latest reply on May 8, 2019 by rdavin



I am working on a C# and .ASP project to update some old code using AF SDK that used to interface with PI collective servers using PIPoints and paths in order to access the data. Now that we are using an AF server, we can simply specify the element and the attribute and retrieve its value from there. The main thing I am trying to do is to retrieve the values of three attributes. I have to retrieve the values of the same three attributes for 1000s of elements depending on what the user specifies, and it seems as if the efficiency of my code isn't great, because it will take upwards of 10 minutes to even access 100 elements. Our old code used to be able to do it in around 30 seconds. Below is a watered down snippet of my code and how I was trying to achieve this:


NOTE: Since I need to retrieve three attributes for each element, there are essentially three loops similar to the one below, each with its own "ATTRIBUTE" specified.

*information about our elements was stored in this table


PISystems myPISystems = new PISystems();
PISystem ourSystem = myPISystems["SERVER INFO"];

AFDatabase ourDb = ourSystem.Databases["DATABASE INFO"];

string elementPath = "";
string attributePath = "";
double example = "";

foreach (myRow in myTable*) {

    elementPath = "PATH TO ELEMENT" + myRow.Identifier;
    AFElement myElement = AFObject.FindObject(elementPath) as AFElement;

    attributePath = "PATH TO ELEMENT" + myRow.Identifier + "ATTRIBUTE_1";
    AFAttribute myAttribute = AFObject.FindObject(attributePath) as AFAttribute;
    example = myAttribute.GetValue(AFTime);



I spent a considerable amount of time in the AF SDK reference but was unable to understand if there was a better way of doing this. Our old code used a method called AFKeyedResults, but as far as I know, that isn't usable for an AF server. The loops work fine to retrieve a small amount of data, but like i mentioned previously, it takes a long time to load data from more than 100 elements. I'm not sure if its a server resources issue, an issue with one specific element that is holding the rest up, or something else entirely. Hopefully I've documented enough here to paint a decent picture of what's going on. Any help or suggestions would be appreciated. Thanks in advance.