8 Replies Latest reply on Feb 12, 2014 4:04 PM by paory

    ProcessBook Automation


      Hi, I used to be able to create an instance of ProcessBook from VBScript using create object. I can't find the ProgID of the ProcessBook application (my registry is locked down here). Please can someone remind me what it is?




      I need to do something along the lines of: 


      app = CreateObject("OSIsoft.ProcessBook.3") ' Or whatever the correct ProgID was. 


      disp = app..Displays.Open(sInputFile, True)


      disp.Width = 1366


      disp.Height = 768


      disp.SaveAs(sOutputFile, pbpdFormatJPEG)




      It used to be that the jpeg would only be rendered if ProcessBook was visible but I'm hoping that's been fixed. It seems to ignore my efforts to set the width and height. Pfffft.

        • Re: ProcessBook Automation

          Hello Jason,


          Please try this:



          Dim app = CreateObject("PIProcessBook.Application.2")


            • Re: ProcessBook Automation

              That's the chap, thanks Gregor

                • Re: ProcessBook Automation

                  My VBScript file kind of works but is not without the usual, er, features.


                  1. The ProcessBook application is momentarily visible and gains focus (tsk-tsk), even though I never instruct it to be visible.


                  2. It generates a 'PI ProcessBook Application has stopped working' error when the app is destroyed unless I do an Application.Quit then Sleep for a few seconds to ensure that the instance has cleaned itself up. It's as if it ignores the usual procedure for garbage collection.


                  3. Setting the Width and Height attributes resizes my display to a similar but by no means identical viewport. :-/


                     Set oApp = CreateObject("PIProcessBook.Application.2")




                     ' Open passed display


                     Set oDisplay = oApp.Displays.Open(sInputFile, True)




                     oDisplay.Width = 1366


                     oDisplay.Height = 768






                     Call oDisplay.SaveAs(sOutputFile, pbpdFormatJPEG)






                  I hope it doesn't leak memory because I intend performing this procedure every minute or so.

                    • Re: ProcessBook Automation

                      I think first problem, the becoming visible and gaining focus, was to do with the fact that I was running some code in the display's OnOpen event. I've moved that code to my VBS.

                        • Re: ProcessBook Automation

                          @Jason: I would be curious to know more about your use case here that needs to perform this routine every minute?


                          Have you thought of using PowerShell instead? This script language interacts well with .NET and COM objects. VBScript has been invented more for web pages and doesn't have the rich variety of functionality that PowerShell has for example.


                          But regarding your code, I think from memory that you would need to tell the automation object that you don't want a visible window/application by doing the following.



                          oApp.Visible = False



                          In general, this is from the best practice to destroy all your objects before leaving an application. VBScript does not escape from this rule. Don't forget here that you don't use the managed code for PI ProcessBook but the COM one and the "garbage collector" exists but it is not as robust as the new one introduced with the .NET Framework.

                            • Re: ProcessBook Automation



                              I would like to do the same script with Powershell.


                              I tried with this script :




                                   $processBook0 = New-Object -ComObject PIProcessBook.Application.2


                                   $display0 =  $processBook0.Displays.Open("c:\MyPDI.PDI")




                              It doesn't works because the "Open" method isn't available..


                              I also tried to use another method :


                                   $processBook1 = New-Object -ComObject PIProcessBook.Application.2




                              This method opens a GUI and I need an automatic script without user action.


                              Do you know another way to open (and save) automatically a PDI with powershell ?



                                • Re: ProcessBook Automation

                                  @Paori: I have written a version for you to utilize. I have chosen to .NET "way" as I like better the syntax but this could have been done with the COM version if you like.


                                  Save this script as OpenAndSavePBDisplays.ps1. You can use as the following:




                                  Save this script as OpenAndSavePBDisplays.ps1. You can use as the following: 

                                  .\OpenAndSavePBDisplays.ps1 "c:\files\mydisplay.pdi" "c:\files\mySavedDisplay.pdi"

                                  OpenAndSavePBDisplays.ps1 file content

                                  # ***********************************************************************
                                  # * Filename:     OpenAndSavePBDisplays.ps1
                                  # * Version:
                                  # ************************************************************************
                                  [CmdletBinding(DefaultParameterSetName="Default", SupportsShouldProcess=$false)]     
                                            [parameter(Mandatory=$true, Position=0, ParameterSetName = "Default")]          
                                            [parameter(Mandatory=$false, Position=1, ParameterSetName = "Default")]
                                            $SavePath = "")
                                       # Add a reference to the PI ProcessBook assemblies.
                                       $refToPBObj = [reflection.assembly]::loadwithpartialname("OSIsoft.PBObjLib")
                                       $pbApp = New-Object PBObjLib.ApplicationClass
                                       $displayHandle = $pbApp.Displays.Open($DisplayToOpen, $true)
                                       # This works for *.pdi format. If you need to change the format, you will need
                                       # to add a validation.
                                       $result = $displayHandle.SaveAs($SavePath, [PBObjLib.pbpdFILEFORMAT]::pbpdFormatDisplay)
                                       if($result) { Write-Host "This operation is a success!"}