7 Replies Latest reply on May 20, 2015 9:21 PM by mullerg

    How to make displays have the same start and end time in Process Book through VBA?

    mullerg

      Hello,

       

      I have some displays that are in the same piw file. In each of them, I have buttons that open the other displays and closes the current one. I want the display that is opened to have the same values of variables of the current display (start time, end time and other variable). How can I accomplish this?

       

      I have tried to do this through Public variables. I declared them in a separate module and set its values on a sub that closes the current display an opens another display. But when the display is opened, the Public variables' values are all empty. What am I doing wrong?

       

      I would appreciate any help!

       

      Thanks

        • Re: How to make displays have the same start and end time in Process Book through VBA?
          bshang

          Hi Gustavo,

           

          This post may be of interest. In particular, the first response by Steve Pilon has some sample code for setting the start and end time for all trends for all displays.

          Set all trends for all displays in ProcBook to use same start and end time

          1 of 1 people found this helpful
            • Re: How to make displays have the same start and end time in Process Book through VBA?
              mullerg

              Hi Barry,

               

              Thanks for your answer!

               

              It is almost what I am looking for. But according to Steve Pilon's code, all the displays must be opened to set theirs start and end time. Is there a way to adapt his code to open only the display called by the button?

               

              Thanks again!

               

              Dim oEntry As PBObjLib.Entry
              Dim oDisp As PBObjLib.Display
              Dim oSymb As PBObjLib.Symbol
              Dim oTrend As PBSymLib.Trend
              Dim idx As Integer

              'Find the "label" of the current display
              Dim strThisDisplayLabel As String
              strThisDisplayLabel = Right(ThisDisplay.Path, Len(ThisDisplay.Path) - InStr(1, ThisDisplay.Path, "!", vbTextCompare))

              'Open all "Embedded Display" entries in the current Workbook
              '(except the current one)
              For Each oEntry In ActiveProcBook.Entries
                  If oEntry.Type = pbEntryPDIEmbeddedInLocalPIW And oEntry.Label <> strThisDisplayLabel Then
                      oEntry.Execute True
                  End If
              Next

              'Browse through all open display entries in the Workbook
              For Each oDisp In ActiveProcBook.Displays
                  'If it is not the current display (where this VBA code resides)
                  If oDisp.Path <> ThisDisplay.Path Then
                      'Browse through all symbols in that display entry
                      For Each oSymb In oDisp.Symbols
                          'If the type of that symbol is "Trend"
                         If oSymb.Type = pbSYMBOLTYPE.pbSymbolTrend Then
                              'Set the trend's start and end times to the
                              'user-specified values entered in the 2 text boxes
                              Set oTrend = oSymb
                              oTrend.SetStartAndEndTime ThisDisplay.txtStartTime.Text, ThisDisplay.txtEndTime.Text
                         End If
                      Next
                      'Close this display and save it
                      oDisp.Close (True)
                  End If
              Next

                • Re: How to make displays have the same start and end time in Process Book through VBA?
                  asorokina

                  Hi Gustavo,

                   

                  You can set the time range for the new display before closing the current one, This way you can access the StartTime and EndTime properties of the current display.

                   

                   

                  In the example below, Display A has a button which opens Display B, sets the time range and closes the Display A.

                   

                  Private Sub Button1_Click(ByVal lvarX As Long, ByVal lvarY As Long)
                  
                  'Open Display B
                  Application.ActiveProcBook.Entries.Item("Display B").Execute (True)
                  
                  'Set the time range for the display B.
                  '(At this point Activedisplay is  the Display B. And ThisDisplay is the Display A.)
                  Application.ActiveDisplay.SetTimeRange ThisDisplay.StartTime, ThisDisplay.EndTime
                  
                  'Close Display A
                  'The Close method doesn't work starting PI Processbook version 2012 due to the bug below
                  '26468OSI8 - ProcessBook 2012 display.close automation method does not close display embedded in PIW 
                  'So "ThisDisplay.Close True" will not work
                  
                  'The workaround is to use hotkeys to close the display. Display A needs to be activated because the workaround with hotkeys only works for an active display. 
                  ThisDisplay.Activate
                  ThisDisplay.Modified = False
                  SendKeys "%FC"
                  
                  End Sub
                  

                   

                  I hope this helps!

                  2 of 2 people found this helpful
                  • Re: How to make displays have the same start and end time in Process Book through VBA?
                    asorokina

                    A side note to the Steve's code snippet - be careful if a ProcessBook file has a lot of display entries. Opening all the displays at the same time can cause a high load on the application in such cases.

                    1 of 1 people found this helpful
                • Re: How to make displays have the same start and end time in Process Book through VBA?
                  ldieffenbach

                  Another approach if your main goal is to synchronize the times...there is built in functionality to do that in PI ProcessBook.

                   

                  Using the highlighted button (above) on the Time Range and Playback toolbar, you can automatically synchronize entire displays. In the example above, I changed the display on the left and then opened the display on the right, which automatically got the same time range represented on the time bar.

                   

                  Regards,

                  Laurie Dieffenbach

                  2 of 2 people found this helpful