3 Replies Latest reply on Mar 23, 2016 3:16 PM by Rhys Kirk

    How can I get a PI Calc expression from a ProcessBook value symbol?

    AdamStidham

      I have the following VBA code for a ProcessBook display:

       

      For Each oSymbol In oDisplay.Symbols

              If oSymbol.Type = pbSYMBOLTYPE.pbSymbolValue Then

                  Set oValue = oSymbol

                  'Need to get PI Calc expression for symbol

                 'oValue.GetTagName(1) returns the name of the PI Calc, but not the expression

              End If

      Next oSymbol

       

      I need to get the PI Calc expression for the value symbol, but oValue.GetTagName(1) only returns the name of the PI Calc and not the PI Calc expression.  How can I get the PI Calc expression for the value symbol?

        • Re: How can I get a PI Calc expression from a ProcessBook value symbol?
          Rhys Kirk

          Here you go...modify it as you need to...

           

          For Each oSymbol In oDisplay.Symbols
                  If oSymbol.Type = pbSYMBOLTYPE.pbSymbolValue Then
                      Set oValue = oSymbol
                         If Not TypeName(oValue.DataPoint) = "Nothing" Then
                         Dim tag As String: tag = oValue.GetTagName(1)
                         Dim ds As PIExpressionDataset
                         Set ds = ThisDisplay.Datasets(Split(tag, ".")(0))
                             Debug.Print ds.Expression
                         Set ds = Nothing
                         End If
                  End If
          Next oSymbol
          
            • Re: How can I get a PI Calc expression from a ProcessBook value symbol?
              AdamStidham

              I get an "Automation Error Unspecified Error" when oValue.DataPoint is called and the DataPoint value is Nothing.  I tested it and confirmed this error occurs just by calling oValue.DataPoint.  Any thoughts?  The solution works when oValue.DataPoint has a Value other than Nothing.

                • Re: How can I get a PI Calc expression from a ProcessBook value symbol?
                  Rhys Kirk

                  Actually, you are probably better doing something like this...

                  For Each oSymbol In oDisplay.Symbols 
                          If oSymbol.Type = pbSYMBOLTYPE.pbSymbolValue Then 
                              Set oValue = oSymbol 
                                On Error Resume Next
                                Dim ds As PIExpressionDataset
                                Set ds = oValue.DataPoint.Dataset
                                    If Err.Number = 0 Then
                                        Debug.Print ds.Expression
                                    End If
                                Set ds = Nothing
                                On Error GoTo 0
                          End If 
                  Next oSymbol