5 Replies Latest reply on Jul 8, 2016 7:34 PM by Chris_Hawkins

    PI Point - Attribute 'pairs'

    Chris_Hawkins

      I know I could work this out by combining varoius AF-SDK routines but also know I'd not create the most efficient solution so ...

       

      ... what is the (best) way of retieveing a list of AF Attribute names and their associated PI Point (if they have one of course). I know that I can do this using AF Builder in EXcel but (1) the list needs post-processing and (2) I'm seeking a programmatic solution.

        • Re: PI Point - Attribute 'pairs'
          Marcos Vainer Loeff

          Hi Chris,

           

          Each AFAttribute has a PIPoint property. Please refer to more information about this property here: AFAttribute.PIPoint Property. This is the easiest way to find a PI Point from an AFAttribute.

           

          Now, if you want to be efficient, you need to optimize the way in order to get all those attributes. If you provide more details about it, we will be able to help you get more efficient.

            • Re: PI Point - Attribute 'pairs'
              pmartin

              To expand upon Marcos' comment, I wrote a very primitive method that would allow you to get the pairs out of your default AF Server.  This method is literally the most inefficient way of doing this search, but hopefully it gives you a good starting point.

               

              public Dictionary<string, string> GetAttributeValuePairings()
              {
                   Dictionary<string, string> pairs = new Dictionary<string, string>();
                   PISystem af = new PISystems().DefaultPISystem;
                   foreach(AFDatabase db in af.Databases) {
                        foreach(AFElement e in db.Elements) {
                              RecursiveSearch(e,pairs);
                         }
                    }
                   return pairs;
              }
              public void RecursiveSearch(AFElement root, Dictionary<string, string> pairs)
              {
                   foreach (AFAttribute a in root.Attributes)
                   {
                        if (a.DataReference != null && a.DataReference.Name.ToLower().Contains("pi point"))
                        {
                             try
                             {
                                  pairs.Add(root.GetPath()+"\\"+a.Name, a.PIPoint.Name);
                             }
                             catch(Exception ex)
                             {
                                  //Console.WriteLine("Error gathering PI Point information for: " + root.GetPath() + "\\" + a.Name);
                             }
              
                        }
                   }
                   foreach (AFElement e in root.Elements)
                   {
                        RecursiveSearch(e, pairs);
                   }
              }
              
              
            • Re: PI Point - Attribute 'pairs'
              dmoler

              If you put all the AFAttribute objects in an AFAttributeList, then you can use the AFAttributeList.GetPIPoint() call to return a keyed collection mapping each AFAttribute to its PIPoint (if there is one).  The keyed result will also include errors in cases where resolution failed.  Because this is done as a bulk call, it will be much faster than one-by-one when you need to process many attributes.

              1 of 1 people found this helpful
                • Re: PI Point - Attribute 'pairs'
                  Chris_Hawkins

                  Thanks David, Paul, Rick and Marcos. My actual need was a little more complex than a pi-af mapping. Some of my attributes have children and some have grandchildren and a third, third-party tag that is also involved! Anyway I adopted the recursive  approach...at least for now. I'm unsure whether there is a  FindAttributes method that returns ALL attributes in one call.

                   

                  Chris

                   

                  Sent from my Windows Phone