5 Replies Latest reply on Jun 13, 2018 1:37 PM by benny

    getting all attributes piaf in visual studio


      I have installed Pi System Explorer and build a tree with my data.

      Now I'm looking for a way to get a full list of all Attributes in all branches of my System Explorer tree. So far I have been using "database.element" where "database" is a reference to my Assetserver but then I only get the elements from the first level of the tree. Not the childs.

        • Re: getting all attributes piaf in visual studio

          Hi Benny,


          Loading all Element Attributes of Database can be time consuming. Therefore I would suggest using one of the AFAttribute.FindElementAttributes overload returning a paged collection. The OSIsoft.AF.Search may offer alternatives which perform better but this depends on how you've build your AF Database and what you finally like to accomplish. If you can share additional information e.g. if you've been using Element and Attribute Templates and what information you like to retrieve, this information could enable us to make suggestions better suited for your use case.

            • Re: getting all attributes piaf in visual studio

              Not only time consuming but resource-intensive. You should only load the attributes that you need--using some of the techniques provided by Gregor--for whatever action you want to take, not the entire list and then sort through like a bucket of Legos.

              • Re: getting all attributes piaf in visual studio
                Rick Davin

                Others have touched upon the idea that it's bad to try to get all of them at once.  Can you share your code?  Sounds like you are trying to crawl over the entire hierarchy but your code doesn't recurse to the child level.


                You could use AFElementSearch to loop through all the elements in a paged manner.  Since you are dealing with attributes, use FindElements(fullLoad: true).  This would bring all elements to you.  It would be up to you to crawl over each element for the attributes, and again, you would have to recurse through the child attributes (and grandchildren, etc.).  We could help you more if you shared your code.

              • Re: getting all attributes piaf in visual studio

                Hi Benny,


                So in agreement with Gregor Beck here in that loading all elements can sometimes take prohibitively long. That being said, some of the Bulk Loading options available in the AF SDK might suit what you need, with LoadByDepth method is specifically what I suspect you want.


                Just some "back of the envelope" coding, as I'm sure there's a more efficient way to do this:


                PISystems myPISystems = new PISystems();
                PISystem myPISystem = myPISystems.DefaultPISystem;
                AFDatabase myDB = myPISystem.Databases.DefaultDatabase;
                AFNamedCollectionList<AFElement> allElements = AFElement.LoadElementsToDepth(
                myDB.Elements, true, 10, 1000);
                AFAttributeList attributes = new AFAttributeList();
                foreach (AFElement element in allElements)
                     foreach(AFAttribute attribute in attributes)



                  • Re: getting all attributes piaf in visual studio

                    Just translated your code to vb.net


                            Dim assetServer As PISystem = New PISystems().Item("XXXyyyzzz")

                            Dim database As AFDatabase = assetServer.Databases("PIAF")

                            Dim allElement As AFNamedCollectionList(Of AFElement) = AFElement.LoadElementsToDepth(database.Elements, True, 10, 1000)

                            Dim element As AFElement

                            Dim attribute As AFAttribute

                            Dim attributes As New AFAttributeList()

                            For Each element In allElement


                                For Each attribute In attributes






                    It works like a charm! And so compact code. Thank you verry much.