2 Replies Latest reply on Jan 8, 2013 11:23 AM by MIPAC

    Extract PI Tag from AF attribute

    Anwar005

      Hi,

       

      I want to extract PI tag Name from AF attribute. I have used below code. But attribute.RawPIPointPath(AFEncodeType.Name) return null always. Does anybody have sample code/project?

       

      My config string for PI point attribute will be one of below strings

      • \\MUS-AS-111\FAH.F013.CHP;UOM=bar
      • \\MUS-AS-111\FAH.F013.THP
      • \\MUS-AS-111\AN.Gross_Production;ReadOnly=False

      Here is the code which I tried to implement. 

       

      string name = attribute.RawPIPointPath(AFEncodeType.Name);
      srcUOM = "";
      if (name != null)
      {
      int index = name.LastIndexOf("\\");
      if (index >= 0)
      name = name.Substring(index + 1);

       

      srcUOM = attribute.DataReference.UOM.Abbreviation;
      }

       

       

       

      Please suggest a solution for this problem?

       

       

       

      Regards,

       

      Anwar

        • Re: Extract PI Tag from AF attribute
          hanyong

          Just like the other post, I've tried doing this in my environment. If I have an attribute with PIPoint reference, the method AFAttribute.RawPIPointPath() gives me the expected path to the PIPoint. I've basically used the code snippet you have posted and implemented my code to get reference to valid element and attributes. 

           

          Again, I don't think your code has a problem, maybe we can look at this more if we have your AF hierarchy and we know how you are getting reference to your AFAttribute.

          • Re: Extract PI Tag from AF attribute
            MIPAC

            RawPIPointPath should work - I have used this in projects before. If you are not adverse to some regular expression fun, you can extract the tag name in a single line of code:

             
            string name = Regex.Match(attribute.RawPIPointPath(AFEncodeType.Name), @"\\\\(.*)\\(.*)").Groups[2].Value;
            

            I know I saw this code snippet somewhere else in the forums, but don't remember exactly where now, so I can't give the proper attribution, but it works very well, and will give you what you are looking for here.

             

            John