15 Replies Latest reply on Sep 13, 2011 8:38 AM by andreas

    Multistate symbol thats based on multiple tags

    ChadB
      Hi, So I have a rectangle that needs to change colors based on four tags.  Sample: 5001_LOLO 5001_LO 5001__HIHI 5001_HI If tag HIHI or LOLO are "ok"  it needs to be red, LO or LOLO "ok"  is yellow, else white At the moment, I am using one multistate symbol and manually adjusting the values but they change so often I can't keep up.  If I could somehow link the state of the symbol to the tags, it will keep me from having to do this.   Thanks. Pi processbook 3.2.0.0
        • Re: Multistate symbol thats based on multiple tags

          One way is to have a PE tag to hold the status of the tag, i.e. HIHI or HI or LO or LOLO or NORMAL - and then use the multi-state to color code the status.  If you can use AF, then you can have this logic in an AF Attribute with formula reference.

            • Re: Multistate symbol thats based on multiple tags
              ChadB

              Totally forgot about doing that.  Thanks!  Worked perfect.

                • Re: Multistate symbol thats based on multiple tags
                  ChadB

                  Without AF, is your suggestion the most efficient way of doing this if I have 200+ tags to do?  Although the tags are of different types (pressure, flow, level, etc.), the tag format is the same so all that needs to be changed is the numbers before the underscore.  I would hate to do all of the tags and then find out there's a much easier way of doing it  :)

                   

                  Thanks again

                    • Re: Multistate symbol thats based on multiple tags
                      Ahmad Fattahi

                      If you are talking about having that many tags in one PE logic, this wouldn't be well manageable at all; I would use PI ACE in that case. But if you have a few tags per PE tag then you can definitely do that. You can use PI Tag Builder add-in to Microsoft Excel to easily make small changes and mass-produce your PE tags.

                        • Re: Multistate symbol thats based on multiple tags
                          ChadB

                          Basically I have taken screenshots of our operation screens and imported them into processbook.  I then overlayed all the tag values .  Every value is in a white rectangle that changes color based on value.  I'm trying to recreate this effect using processbook.  I'm not sure that I have access to PI ACE.  Just to make sure I have it explained it clearly;  I have about 25 values on my first page and I am wanting to put a rectangle behind them that dynamically changes colors.  The above method works, its just time consuming.

                           

                          Thanks

                            • Re: Multistate symbol thats based on multiple tags

                              I think what Gopal suggests is probably your best bet, because if I understand you correctly for each 'Value' you have 4 'limit' tags associated.  So for every 'Value' you have a Performance Equation with the 4 'limit' tags as input, which gives you the status as an output.  You then multistate based on that status.  For every value tag you then build a PE status tag and associate with each rectangle.

                               

                              When you say it is time consuming, in what way?  Defining the PE for the status tag?  Or setting the multistate for the rectangle symbols based on the value?  Both of these activities can be automated with a snippet or two of code.

                                • Re: Multistate symbol thats based on multiple tags
                                  ChadB

                                  I'm interested in how I can automate this with code.  

                                    • Re: Multistate symbol thats based on multiple tags

                                      First, if you list all your value tags, status tags and limit tags you can build your PE syntax on mass, something like the following:

                                       

                                      excelscreenshot.png_2D00_480x320.png

                                       

                                       

                                       
                                      ="IF ('" &D2 & "'=""OK"" OR '" & E2 & "'=""OK"") THEN 2 ELSE (IF ('" & F2 & "'=""OK"" OR '" & G2 & "'=""OK"") THEN 1 ELSE 0)"
                                      

                                       Use PI SMT to create your PEs.

                                       

                                      Then the following code (not handling errors!) should do the trick of creating the symbols and multi stating the rectangle.

                                       

                                       

                                       
                                      Sub AddRectangleWithValue()
                                      
                                      Const srvName As String = "\\localhost\"
                                      
                                      Dim app As Excel.Application
                                      Set app = New Excel.Application
                                          
                                          Dim WB As Excel.Workbook
                                          Set WB = app.Workbooks.Open("C:\ListOfValues.xlsx")
                                          
                                              Dim WS As Excel.Worksheet
                                              Set WS = WB.Worksheets("Sheet2")
                                                  
                                                  Dim i As Integer, lastTop As Integer: lastTop = 15000
                                                  For i = 2 To 1000
                                                      If WS.Range("A" & i).Value = "" Then Exit For
                                                      
                                                      Dim rect As Rectangle, val As Value
                                                      Set rect = ThisDisplay.Symbols.Add(pbSymbolRectangle)
                                                          rect.Width = 200
                                                          rect.Height = 100
                                                          rect.Left = -15000
                                                          rect.Top = lastTop - rect.Height: lastTop = lastTop - rect.Height
                                                          
                                                          Call MultiStateSymbol(rect, srvName & WS.Range("C" & i).Value)
                                                          
                                                          Set val = ThisDisplay.Symbols.Add(pbSymbolValue)
                                                              Call val.SetTagName(srvName & WS.Range("B" & i).Value)
                                                              
                                                              val.Left = rect.Left + (rect.Width / 2) - (val.Width / 2)
                                                              val.Top = rect.Top - (rect.Height / 2) + (val.Height / 2)
                                                          
                                                          rect.Name = "AUTORECT_" & rect.Name
                                                          val.Name = "AUTOVAL_" & val.Name
                                                          
                                                      Set val = Nothing
                                                      Set rect = Nothing
                                                  Next i
                                                  
                                              Set WS = Nothing
                                          
                                          Set WB = Nothing
                                      
                                          app.Quit
                                      Set app = Nothing
                                      
                                      End Sub
                                      
                                      Sub MultiStateSymbol(ByVal TheSymbol As Symbol, ByVal point As String)
                                      
                                      Dim MS As MultiState, MSS As MSState
                                      Set MS = TheSymbol.CreateMultiState(point)
                                          MS.BlinkBadData = True: MS.ColorBadData = pbRed
                                          MS.StateCount = 3
                                          
                                          If MS.DefineState(1, 0, 1) Then Set MSS = MS.GetState(1): MSS.Color = pbWhite
                                          If MS.DefineState(2, 1, 2) Then Set MSS = MS.GetState(2): MSS.Color = pbYellow
                                          Set MSS = MS.GetState(3): MSS.Color = pbRed
                                          
                                      Set MS = Nothing
                                      
                                      End Sub
                                      

                                       

                                       

                                      I used some assumptions but change to suit your needs.