5 Replies Latest reply on Mar 26, 2009 4:49 PM by arash.khoddamy

    ttsym.GetTagName return the Wrong Pi Tag

    arash.khoddamy

      I have written a custom tooltip application. But we noticed that for Tag names that that have a period in them the ttsym.GetTagName(TrendTraceNo) returns the wrong Tagname. I have to note that this only happens for tags with period in the name for all other tags everything works fine.

       

      The tag names in question all have the form Tag.modifier.

       

      So Here are the Tag names that we have trended

       

      SCA_RES_Forebay_Lvl_00
      SCA_RES_Forebay_Lvl_00.NMin
      SCA_RES_Forebay_Lvl_00.NMax
      SCA_RES_Forebay_Lvl_00.DSNotice
      SCA_RES_Forebay_Lvl_00.DSIncident

       

      It seems that the ttsym.GetTagName(TrendTraceNo) does not get the full Tagname and stops at the period. When I put a message box on display the output form ttsym.GetTagName(TrendTraceNo) I only get “SCA_RES_Forebay_Lvl_00” no matter what tag I am on.

       

      My code is as follows

       

      For Me.TrendTraceNo = 1 To ttsym.PtCount 
         
         If InStr(Left(Tooltip, InStr(1, Tooltip, "=") - 2), Right(CStr(ttsym.GetTagName(TrendTraceNo)), (Len(CStr(ttsym.GetTagName(TrendTraceNo))) - InStr(3, CStr(ttsym.GetTagName(TrendTraceNo)), "\")))) > 0 Then
         
              Exit For
          
          End If
          
      Next TrendTraceNo

      ' Get PI server and Tagname for this value.
      PIServerNameTagName = ttsym.GetTagName(TrendTraceNo)
          
      ' Get this value's PI Server name
      PIServerName = Mid(PIServerNameTagName, 3, (InStr(3, PIServerNameTagName, "\") - 3))
          
      ' Get this value's PI Tagname
      PITagName = Right(PIServerNameTagName, (Len(PIServerNameTagName) - InStr(3, PIServerNameTagName, "\")))

       

      The problem comes when I use the TrendTraceNo to get the Tagname. For all traces I get the base Tagname ending at the period. So for the example above no matter what tag I hover over I only get “SCA_RES_Forebay_Lvl_00” as the Tagname

       

      It seems that the ttsym.GetTagName(TrendTraceNo) does not get the full tagname and stops at the period. When I put a messebox on display the output form ttsym.GetTagName(TrendTraceNo) I only get “SCA_RES_Forebay_Lvl_00” no matter what tag I am on.

       

      Is there another way i can get the tagname that won't haev this problem?

        • Re: ttsym.GetTagName return the Wrong Pi Tag
          arash.khoddamy

          Ops it turns out the problem is with me this line

           

           

          For Me.TrendTraceNo = 1 To ttsym.PtCount
             
              If InStr(Left(Tooltip, InStr(1, Tooltip, "=") - 2), Right(CStr(ttsym.GetTagName(TrendTraceNo)), (Len(CStr(ttsym.GetTagName(TrendTraceNo))) - InStr(3, CStr(ttsym.GetTagName(TrendTraceNo)), "\")))) > 0 Then
              
                  
          Exit For
              
              End If
              
          Next TrendTraceNo

           

          Sine the tag with no modifiers (no period) SCA_RES_Forebay_Lvl_00 was the first trace. As I looped to find the trace the user was on , the instr function was matching it to the first trace since SCA_RES_Forebay_Lvl_00  is in SCA_RES_Forebay_Lvl_00.DSNotice and there for not cycle through the full list of points.

           

          At this point I am just parsing the default tooltip to get the tag. But is there a better way to see which trance in the trend the user is over with the mouse.

           

          The Problem :

           

           I am modifying the tooltip but on the trend object how do i know which trace the user is on?

           

          I am coding in vb.net and the custom tooltip is vb.net add-in using pi toolbar add-in template.

            • Re: ttsym.GetTagName return the Wrong Pi Tag
              dhollebeek

              Sorry, there's currently no way (via automation) to know what trace on a trend the mouse is hovering over.

                • Re: ttsym.GetTagName return the Wrong Pi Tag
                  MikeReid

                  The trend tooltip only shows entries for tags at the cursor - but there might be multiple rows.

                   

                  The easiest way to process the text, is to use the split() function to create arrays from the initial string.

                   

                  (This is the way I do it in VBA, but there will be a similar string function in .Net)

                   

                   

                   

                  Remember that the tooltip can describe annotation markers as well as trace values, so you need to check for these conditions.

                   

                  This is an extract of VBA code:


                          Dim strRows() As String
                          Dim i As Integer
                          Dim intNumRow As Integer
                          Dim strTemp1() As String
                          Dim strTemp2() As String
                          Dim strTemp3() As String
                          Dim strTemp4() As String
                          Dim strRefTime As String
                          Dim strRowData As String
                          Dim objTrend As PBSymLib.Trend

                          ' We get here with a blank tooltip if the cursor is on the graph area -
                          ' but not on a trace.
                          If ToolTip <> "" Then
                              Dim strArray() As String
                             
                              strArray = Split(ToolTip, " ")
                             
                              If UBound(strArray) > 1 And strArray(1) = "=" Then
                                  ' Get the time from the first row of the original tooltip.
                                  strRefTime = ""
                                  strRows = Split(ToolTip, vbLf)
                                 
                                  strTemp1 = Split(strRows(0), "=")
                                  If UBound(strTemp1) = 1 Then
                                      strTemp2 = Split(strTemp1(1), "(")
                                      If UBound(strTemp2) = 1 Then
                                          strTemp3 = Split(strTemp2(1), ")")
                                          If UBound(strTemp3) = 1 Then
                                              strRefTime = strTemp3(0)
                                          End If
                                      End If
                                  End If
                                     
                                  ' If we got a reference time - get the cursor data.
                                  ' PATCH - This shows a tool tip for each trace - not just those near the cursor.
                                  If strRefTime <> "" Then
                                      Set objTrend = ttsym
                                      ' PATCH - this version shows old and new formats.
                                      'ToolTip = ToolTip & vbLf & "Time: " & strRefTime
                                      ToolTip = "Time: " & strRefTime
                                      ' Get data for each trace.
                                      For i = 1 To objTrend.TraceCount
                                          strRowData = "  Row " & i & " Tag = " & objTrend.GetTagName(i)
                                          strRowData = GetTrendValueText(objTrend.GetTagName(i), strRefTime)
                                          If Len(strRowData) > 0 Then
                                              ToolTip = ToolTip & vbLf & "  " & strRowData
                                          End If
                                      Next
                                  Else
                                      ToolTip = " Could not get time for cursor data."
                                  End If
                              Else
                                  ' The inital text format does not appear to be a value message.
                                  ' Leave the original message alone - it is probably a notification
                                  ' item from PB3.
                              End If
                          End If

                   

                    • Re: ttsym.GetTagName return the Wrong Pi Tag
                      MikeReid

                      Ok - here is a better version.

                       

                      This one takes the actual tooltip text, and reformats it:

                      • Remove the server name
                      • Add the units and description if available.

                      '===============================================================================
                      '
                      ' NAME:         TrendToolTipText
                      '
                      ' DESCRIPTION:
                      '   Generate standard tooltip text for a trend.
                      '
                      ' PARAMETERS:
                      '   IN:     ToolTip     - The initial tool tip text.
                      '
                      ' RETURN VALUE:
                      '   New tooltip text.
                      '
                      ' SIDE EFFECTS:
                      '   None.
                      '
                      '===============================================================================

                      Private Function TrendToolTipText(ByVal ToolTip As String) As String
                      Dim strTooltip
                      Dim strRows() As String
                      Dim i As Integer
                      Dim strArray() As String
                      Dim intNumRow As Integer
                      Dim strTemp1() As String
                      Dim strTemp2() As String
                      Dim strFullTag As String
                      Dim strShortTag As String
                      Dim strValue As String
                      Dim strTime As String
                      Dim strDesc As String
                      Dim strUnits As String
                      Dim intType As Integer

                          On Error GoTo ErrHan

                          If ToolTip <> "" Then
                            
                              ' Check that the tooltip looks like it contains a value report.
                              strArray = Split(ToolTip, " ")
                              If UBound(strArray) > 1 And strArray(1) = "=" Then
                             
                                  ' Process each row in the tooltip
                                  strRows = Split(ToolTip, vbLf)
                                  strTooltip = ""
                                 
                                  For i = 0 To UBound(strRows)
                                      strTemp1 = Split(strRows(i), " ")
                                      strFullTag = strTemp1(0)
                                      strTemp2 = Split(strFullTag, "\")
                                      If UBound(strTemp2) = 3 Then
                                          strShortTag = strTemp2(3)
                                          intType = PDMS_SDK.GetPIPointAttribute(strFullTag, "PointType")
                                          strDesc = PDMS_SDK.GetPIPointAttribute(strFullTag, "Descriptor")
                                          strUnits = PDMS_SDK.GetPIPointAttribute(strFullTag, "EngUnits")
                                      Else
                                          ' Probably a data set.
                                          strShortTag = strFullTag
                                      End If
                                     
                                      strTemp1 = Split(strRows(i), "=")
                                      strTemp2 = Split(strTemp1(1), "(")
                                      If strUnits <> "" Then
                                          strValue = strTemp2(0) & " " & strUnits
                                      Else
                                          strValue = strTemp2(0)
                                      End If
                                      strTime = " at (" & strTemp2(1)
                                     
                                      If strDesc <> "" Then
                                          strTooltip = strTooltip & strShortTag & " (" & strDesc & ")" & vbLf & _
                                                       "    = " & strValue & strTime
                                      Else
                                          strTooltip = strTooltip & strShortTag & " = " & strValue & strTime
                                      End If
                                      If i < UBound(strRows) Then
                                          strTooltip = strTooltip & vbLf
                                      End If
                                  Next i
                              Else
                                  ' The inital text format does not appear to be a value message.
                                  ' Leave the original message alone - it is probably a notification
                                  ' item from PB3.
                              End If
                          Else
                              ' We get here with a blank tooltip if the cursor is on the graph area -
                              ' but not on a trace.
                              strTooltip = ToolTip
                          End If

                      Cleanup:
                          TrendToolTipText = strTooltip
                          On Error GoTo 0
                          Exit Function

                      ErrHan:
                      '    MsgBox "ThisDisplay.TrendToolTipText: Error " & _
                      '           Err.Number & " (" & Err.Description & ")", _
                      '           vbCritical, "PDMS"
                          GoTo Cleanup
                      End Function