7 Replies Latest reply on Dec 17, 2010 8:42 AM by hanyong

    Opening Element Relative ProcessBook Display From Excel

    espo89

      I'm trying to open a ProcessBook display which is element relative from within some VBA code in excel.   What appears to be happening is the display opens, however the "Element Relative Display" Task pane does not, esentially giving the display no context to act on.   My ultimate goal is to open the display, set the start and end times, set the element context, then save the display back out as a graphics file (to then be loaded into some reports).  

       

      Also, whenever I try and set or even display the current context of the display,  I get the standard "Object or with variable not set" showing there is actually no contexthander created for the display.

       

      The function I'm using (without the context setting part) is:

       
      Private Sub cmbRun_Click()
      
          Dim PBfile As String
          Dim OutputFile As String
          Dim Context As String
          Dim StartTime As String
          Dim EndTime As String
          Dim ErrorStr As String
          Dim PBApp As PBObjLib.Application
          Dim PBDisplay As PBObjLib.Display
          
          ' Get input values from Sheet
          PBfile = Range("C4").Value
          StartTime = Range("C5").Value
          EndTime = Range("C6").Value
          Context = Range("C7").Value
          OutputFile = Range("C8").Value
          
          'Load ProcessBook
          On Error Resume Next
          Set PBApp = GetObject(, "piprocessbook.application.2")
          On Error GoTo RunError
          If PBApp Is Nothing Then
              Set PBApp = CreateObject("piprocessbook.application.2")
          End If
          
          'Open the display
          Set PBDisplay = PBApp.Displays.Open(PBfile, 1)
              
          Call PBDisplay.SetTimeRange(StartTime, EndTime)
          Call PBDisplay.SaveAs(OutputFile, pbpdFormatJPEG)
          
          Exit Sub
          
      RunError:
          ErrorStr = "Error Number: " & Err.Number & vbCrLf
          ErrorStr = ErrorStr & "Error Description: " & Err.Description
          MsgBox ErrorStr, vbCritical + vbOKOnly
       
      End Sub
      

       What am I missing such that the display doesn't have any context when it's opened?   Note that the display opens fine when using "File->Open" in processbook and the element Relative addin in PB is loaded at startup.  Also, the above code is able to set the time range and output to a jpg fine.

       

      I've also tried using:

       
      'Open the display
          Set PBDisplay = PBApp.ProcBooks.Open(PBfile)
      

       To open the display as detailed in the Process Book ActiveX Scripting course materials (I think it's in chapter 5) and get the same results.

        • Re: Opening Element Relative ProcessBook Display From Excel
          hanyong

          Hi Randy,

           

          Whats the code that you are using to set the context of the display? and does the display that you open in the VBA code has a dynamic symbol (Trend, Value, Bar) that is referencing to a Element Relative Context?

           

          I've tried to run your code to open a display that has a trend referencing a Element Relative context. It does open and set the display with the context that I specify in Excel VBA, here's the code that I've used:

           
          Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
          Sub Button1_Click()
              Dim PBfile As String
              Dim OutputFile As String
              Dim Context As String
              Dim StartTime As String
              Dim EndTime As String
              Dim ErrorStr As String
              Dim PBApp As PBObjLib.Application
              Dim PBDisplay As PBObjLib.Display
               
              ' Get input values from Sheet
              PBfile = "C:\users\hanyong\documents\test2.pdi"
              StartTime = "*-1h"
              EndTime = "*"
              Context = "\\HANYONGE4310\AFDB\Meters\Meter-XF222"
              OutputFile = "C:\users\hanyong\documents\test2.jpg"
               
              'Load ProcessBook
              On Error Resume Next
              Set PBApp = GetObject(, "piprocessbook.application.2")
              On Error GoTo RunError
              If PBApp Is Nothing Then
                  Set PBApp = CreateObject("piprocessbook.application.2")
              End If
               
              'Open the display
              Set PBDisplay = PBApp.Displays.Open(PBfile, 1)
              
              PBDisplay.ContextHandlers("E").CurrentContext(PBDisplay) = Context
              Call PBDisplay.SetTimeRange(StartTime, EndTime)
              
              Sleep (1000)
              Call PBDisplay.SaveAs(OutputFile, pbpdFormatJPEG)
               
              Exit Sub
               
          RunError:
              ErrorStr = "Error Number: " & Err.Number & vbCrLf
              ErrorStr = ErrorStr & "Error Description: " & Err.Description
              MsgBox ErrorStr, vbCritical + vbOKOnly
          End Sub
          

          Note: I added a delay (Sleep) after the setting of the context and time and before saving the display as jpg, otherwise the jpg file will not be saved properly.

           

           

          • Re: Opening Element Relative ProcessBook Display From Excel

            Randy Esposito

            My ultimate goal is to open the display, set the start and end times, set the element context, then save the display back out as a graphics file (to then be loaded into some reports).
            Out of curiosity, can you share a little more about that reporting environment you are planning to send PB graphics into?