9 Replies Latest reply on Feb 27, 2012 1:33 PM by andreas

    ProcessBook VB.NET Docking Window add-in in VB

    mjarvis

      Hey Guys,

       

      I'm trying to build an add-in to processbook with a docking window. I found some sample code and templates to start with, now I'm having trouble displaying an active X control inside the docking window. I think the TryCast statements are not working well. The examples I'm looking at are done in C#, so its mainly a C# to VB conversion issue. The full project is attached, working on possibly getting the EventFrame add-in a head start.

       

       

       
              Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As Extensibility.ext_ConnectMode, ByVal AddInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
                  Try
                      app = CType(Application, PBObjLib.Application)
                      m_dockWindow = app.DockWindows.Add(PBObjLib.pbDockWindowType.pbTypeSingleViewWindow, "Simple Window", PBObjLib.pbDockPosition.pbDockLeft, False)
      
                      m_dockWindow.Visible = True
                      m_dockWindow.Width = 250
                      m_dockWindow.Title = "Visible Title"
                       m_dockWindow.Views.Add(PBObjLib.pbViewType.pbControlViewType, "EventFrameSearch")
      
                      'MJAR trycast statements
                      Dim MyView As PBView = m_dockWindow.Views.Item("EventFrameSearch")
                      Dim MyPBControlView As PBControlView = TryCast(MyView, PBControlView)
                      Dim labcntrl As System.Windows.Forms.Label = TryCast(MyPBControlView.CreateControl("Forms.Label.1"), System.Windows.Forms.Label)
                      labcntrl.Text = "Label Control"
      
                       MsgBox("Hello World")
                      'Dim MyView As PBView = m_dockWindow.Views.Item("EventFrameSearch")
                       ''MJAR trycast statements
      
                      'Dim MyPBControlView As PBControlView = TryCast(MyView, PBControlView)
                      ''MyPBControlView.CreateControl("Event.Frame")
                      'Dim MyEventFrameTree As OSIsoft.AF.UI.AFViewControl
                      'Dim MyPBControl As PBControl = MyPBControlView.CreateControl("Event.Frame")
      
                   Catch ex As Exception
                      MsgBox("Exception on Connection : " + ex.Message)
                  End Try
              End Sub
      

       

          • Re: ProcessBook VB.NET Docking Window add-in in VB
            mjarvis

            That worked! Really wish I could have found that thread a little bit easier.

              • Re: ProcessBook VB.NET Docking Window add-in in VB
                mjarvis

                 

                 
                Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As Extensibility.ext_ConnectMode, ByVal AddInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
                            Try
                                app = CType(Application, PBObjLib.Application)
                                m_dockWindow = app.DockWindows.Add(PBObjLib.pbDockWindowType.pbTypeSingleViewWindow, "Simple Window", PBObjLib.pbDockPosition.pbDockLeft, False)
                                m_dockWindow.Visible = True
                                m_dockWindow.Width = 250
                                m_dockWindow.Title = "Visible Title"
                
                                Dim ctrlView As PBObjLib.PBControlView = CType(m_dockWindow.Views.Add(PBObjLib.pbViewType.pbControlViewType, "Search"), PBObjLib.PBControlView)
                                Dim usrCtrl As MyAFTree1 = DirectCast(ctrlView.CreateControl("MJProjName.MyAFTree1"), MyAFTree1)
                
                                'app.ActiveDisplay.SetTimeRange("*-24H", "*-12H")
                            Catch ex As Exception
                                MsgBox("Exception on Connection : " + ex.Message)
                            End Try
                        End Sub
                

                 

                 

                 

                 

                 

                  • Re: ProcessBook VB.NET Docking Window add-in in VB
                    mjarvis

                    Ok, so my next problem is I need to be able to set the app.ActiveDisplay.SetTimeRange with the time ranges from the add-in class. From the Add-in Class (MyAFTree.vb) I can grab the start and end times, and display them in a pop-up window when I double click on them. I want to change the display start and end times.

                     

                     

                     

                     

                     
                        Private Sub AfViewControl1_ItemDoubleClick(ByVal sender As System.Object, ByVal e As OSIsoft.AF.UI.SelectionChangeEventArgs) Handles AfViewControl1.ItemDoubleClick
                            MsgBox(AfViewControl1.AFSelection.ToString & " This is the EF Name, maybe set the name of the trend?")
                    
                            Dim MyEventFrame As AFEventFrame = DirectCast(AfViewControl1.AFSelection, AFEventFrame)
                            MsgBox(MyEventFrame.StartTime.ToString & "  " & MyEventFrame.EndTime.ToString & "  This is the start and end times, need to set the display.startime and display.endtime")
                    
                            'cannot access app from this class
                        End Sub
                    

                     

                     

                    I'm think I should implement a Public > Get, Set method in MyAFTree class, and pass them to the connect class? But I need the parameters to be sent when the user interacts with AfViewControl1_ItemDoubleClick 

                     

                    Full project attached, it currently loads the addin to Processbook, you can search for event frames and add them to a tree, then when you click on the event frame, it tells you the start and end times.

                     

                     

                      • Re: ProcessBook VB.NET Docking Window add-in in VB
                        mjarvis

                        Ok, nevermind. I CAN access the app from the green comment. Brain delay.

                          • Re: ProcessBook VB.NET Docking Window add-in in VB
                            mjarvis

                            Ok, back to not being able to use the app in my add-in class. I need to be able to grab the app object somehow in the add-in class. In the normal connect class, the app is passed from the OnConnection Sub. I saw in the ERD Code review that the ERD add-in is able to access things like display.NamedValues from a class that is not the connect class. I think I'm missing something here. Any ideas on this one?

                             

                             

                             
                                Private Sub AfViewControl1_ItemDoubleClick(ByVal sender As System.Object, ByVal e As OSIsoft.AF.UI.SelectionChangeEventArgs) Handles AfViewControl1.ItemDoubleClick
                                    Dim MyEventFrame As AFEventFrame = DirectCast(AfViewControl1.AFSelection, AFEventFrame)
                                    Dim app As PBObjLib.Application
                                    'CType(Application, PBObjLib.Application)
                            
                                    'For debugging
                                    MsgBox(MyEventFrame.StartTime.ToString & "  " & MyEventFrame.EndTime.ToString & "  This is the start and end times, need to set the display.startime and display.endtime")
                            
                                    Dim EFStartTime As String = MyEventFrame.StartTime.ToString
                                    Dim EFEndTime As String = MyEventFrame.StartTime.ToString
                            
                            
                                    Try
                                        app.ActiveDisplay.SetTimeRange(EFStartTime, EFEndTime)
                                    Catch ex As Exception
                                        'get object reference not set to an instance of an object
                                        MsgBox("Error setting time " & ex.Message)
                                    End Try
                            
                                End Sub