3 Replies Latest reply on Dec 16, 2013 6:27 PM by mhamel

    ProcessBook Custom Docked Window Add-in (c#), Changing Context of ERD

    Dag Reppen

      Hello,

       

       I am creating a ProcessBook add-in that is a variation of the current Element Relative docked window. I have created the TreeView, but am having difficulty changing the context when a node is clicked. While I have written this type of code in a VBA macro, I have been unable to translate into a c# application. (see attempt below)

       
              private PBObjLib.Application app;
              private void trview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
              {
                  this.app = (PBObjLib.Application)app;
                  ContextHandler ch = app.ContextHandlers.Item("E");
                  Display MyDisplay = app.ActiveDisplay;
                  ch.CurrentContext(MyDisplay) = e.Node.Name;
              }
      

       I suppose the two main areas that are giving me trouble are (1) establishing the 'app' variable as the currently open ProcessBook session and (2) finding the correct function to change the context.

       

      Thank you for your assistance.

        • Re: ProcessBook Custom Docked Window Add-in (c#), Changing Context of ERD
          dhollebeek

          1) ThisDisplay.Application is what you want (we store a cached copy on Display.Activate in our own applications.  The code you have there just casts an uninitialized value.

           

          2) ch.CurrentContext(MyDisplay) = <af path>

           

          For #2 you are going to have to pass in or otherwise cached the currently selected element (the names don't have to be unique) and then use afElement.GetPath()

            • Re: ProcessBook Custom Docked Window Add-in (c#), Changing Context of ERD
              Dag Reppen

              David,

               

              Thanks for your response. Could you possibly provide a code snippet using the functions you mentioned? I am trying to incorporate those but am still receiving errors. Should I be setting 'app' equal to ThisDisplay.Application?

               

               And with CurrentContext I am getting the error "...cannot be used like a method."

               

               

                • Re: ProcessBook Custom Docked Window Add-in (c#), Changing Context of ERD
                  mhamel

                  @Dag: The app variable is referenced and cast during the OnConnection method. You can manipulate the global variable when you want with the trview_NodeMouseClick method.

                   

                   

                   
                  public void OnConnection(object app, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
                  {
                       try
                       {
                            this.app = (PBObjLib.Application)app;
                            this.AddDockWindow();
                       }
                       catch (System.Runtime.InteropServices.COMException comEX)
                       {
                            System.Diagnostics.Debug.Print("OnConnection " + comEX.Message);
                            System.Diagnostics.Debug.Assert(false, comEX.Message);
                       }
                       catch (Exception ex)
                       {
                            System.Diagnostics.Debug.Print("OnConnection " + ex.Message);
                            System.Diagnostics.Debug.Assert(false, ex.Message);
                       }
                  }
                  
                  //...
                  
                  private void trview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
                  {     
                       ContextHandler ch = this.app.ContextHandlers.Item("E");
                       Display MyDisplay = this.app.ActiveDisplay;
                       ch.CurrentContext(MyDisplay) = e.Node.Name;
                  }