11 Replies Latest reply on Mar 23, 2016 4:34 PM by Chris_Hawkins

    PI-AF Reference Types

    Chris_Hawkins

      I'm attempting to interogate a PI-AF Database to determine the reference types of each Element. While I can create new references I have as yet been unable to work out the code I need (in VB.NET or C#) to determine these relationships as I step through the elements. To summarise:

      1. I start with Elements / Sub-elements in a conventional parent-child reference (relationship) structure
      2. There are additional / replacement references (relationships) between children of one parent and the parent of other children. Somewhat akin
        to ‘uncle/aunt and nephew/niece’. So I c
        reate a new relationship. Let's say Uncle-Nephew and drag elements to their 'uncle(s)'
      3. What I have yet to get working is how – in VB.NET/C# with PI AF SDK  – I determine the reference type of a particular AF Element. Essentially
        “who is/are my uncles?” or “who is/are my nephew(s)”.

      Thanks in advance for to anyone who can advise.

      Chris

        • Re: PI-AF Reference Types
          Rhys Kirk

          You use the GetParents() method to obtain the parents of a particular Element. You can then use the Parent with the GetReferenceTypes() method and specifying the child you want to know about. For example:

           

                      AFElement e = db.Elements["Element1"].Elements["Element1_1"];
                      var parents = e.GetParents(OSIsoft.AF.AFSortField.Name, OSIsoft.AF.AFSortOrder.Ascending, 1000);
                      foreach(AFElement parent in parents)
                      {
                          var refType = parent.GetReferenceTypes(e);
                      }
          

           

          Just to add, AFElement.Parent will give you the "real" Parent.

          2 of 2 people found this helpful