Author Topic: Addin Example in C#  (Read 10874 times)


  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • !
    • View Profile
Addin Example in C#
« on: December 01, 2003, 04:49:30 am »
Hi All,
    I have started working on an addin and had some trouble getting the one example working. I eventually worked out the problems, and wanted to post a more detailed example. Hope this helps others get a faster start on developing addins.

The addin should behave as follows if built and configured correctly, otherwise, you should get an error when starting EA, or errors when compiling...

1. The "MyAddin connected" msgbox should display before the EA main program displays
2. The "Add-Ins" main menu option should be visible once EA is loaded.
3. The "MyAddIn" submenu should appear under the "Add-Ins" main menu.
4. Clicking the "MyAddIn" submenu should display the "Not implimented" msgbox
5. Exiting EA should display the "MyAddin disconnected" msgbox

//--------------------- start of class -------------
using System;
using System.Runtime.InteropServices;   // needed for the Guid and ClassInterface attributes

namespace MyAddIn  
   [Guid  ("1602B4A3-AE64-4a9e-812F-AC08613E0962"),
   public class EAAddIn : EAAddInTemplate.Addin  

       /// <summary>
       /// Summary description for Class1.
       /// </summary>
       public EAAddIn()
           // TODO: Add constructor logic here
       #region "AddinMembers"

       public void ShowHelp(string MenuName, string ItemName)
           // TODO:  Add EAAddIn.ShowHelp implementation

       public void MenuClick(ref EA.Repository Repository, string MenuName, string ItemName)
           // TODO:  Add EAAddIn.MenuClick implementation
           System.Windows.Forms.MessageBox.Show( "Not implimented" );

       public object GetMenuItems(string MenuName)
           // TODO:  Add EAAddIn.GetMenuItems implementation
           //return null;
           return "&MyAddIn";

       public void FileOpen(ref EA.Repository Repository)
           // TODO:  Add EAAddIn.FileOpen implementation

       public void Connect(ref EA.Repository Repository)
           System.Windows.Forms.MessageBox.Show( "MyAddin connected" );

       public void Disconnect()
           System.Windows.Forms.MessageBox.Show( "MyAddin disconnected" );

//--------------------- end of class -------------

The registry info threw my for a while. I kept getting an error loading the COM object in EA. In my example, I set my Project default namespace to MyAddIn to match the namespace in my class file. This is found in the Project Properties dialog under Common Properties/General/Default Namespace. Note the capital "I" in MyAddIn.

//--------------------- start of registry info -------------

[HKEY_CURRENT_USER\Software\Sparx Systems\EAAddins\MyAddIn]
//--------------------- end of registry info -------------

Several references are required for this example to work. The first 2 are described in the EA documentation, and the other is the Forms reference so the msgbox calls work.

//--------------------- start of reference info -------------
EA      // EA.TLB
EAAddInTemplate   // Addn_tmpl.TLB
//--------------------- end of reference info -------------