The complete Enterprise Architect C# add-in template

Override EA Event drop-down

In the post Tutorial: Create your first C# Enterprise Architect addin in 10 minutes you can find a basic template that can be used to create C# add-ins for Enterprise Architect.

But this basic template is far from complete. The EA API provides a whole set of  “events” that can be used in an add-in.
To use one of these events you have to create a public operation in the add-in class that contains the signature of the event. EA will then call that operation at the appropriate time so you can execute your behavior.

The problem is that the documentation of the EA API contains all of those operation signatures in VB syntax, so each time you want to use such an event in your C# add-in you’ll have to translate it to C# syntax.

To save myself the trouble each time I have to write a new add-in I created an abstract base class that contains all of the events defined by EA.

Usage instructions

  • Download the EAAddinBase.cs from the GitHub repository
  • Create a new class library project and add the EAAddinBase.cs to the project
  • Create a new add-in class that extends EAAddinBase.cs, see MyAddin.cs for inspiration

<br />
namespace MyAddin<br />
{<br />
    public class MyAddinClass : EAAddinFramework.EAAddinBase<br />
    {<br />

  • Override any EA event you wish to use. Typing “public override ” should get you a nice drop-down list of all available events, complete with documentation.

    Override EA Event drop-down
    Override EA Event drop-down
  • Follow the instructions in Tutorial: Create your first C# Enterprise Architect addin in 10 minutes in order to make your assembly COM Visible, register the assembly for COM Interop and create the registry key.
  • Build your project
  • Open up EA and test your add-in.

More resources

Related blog posts

Source code on GitHub

Sparx Systems

Other

  • Examples in the EA installation folder: C:\Program Files\Sparx Systems\EA\Code Samples

7 thoughts on “The complete Enterprise Architect C# add-in template

  1. Many thanks for your work. I am ecountering a difficulty using the framework. I’m trying to use EA_OnPostNewElement which list EventProperties as a parameter. In the current version, it isn’t an ElementID at all. It’s an interface from which I don’t see how I get to the ID.

    namespace EA
    {
    [TypeLibType(4176)]
    [Guid(“467A0238-AF16-4378-B576-AC0C8D909AC9”)]
    public interface _EventProperties : IEnumerable
    {
    [DispId(1)]
    int Count { get; }
    [DispId(2)]
    ObjectType ObjectType { get; }

    [DispId(0)]
    EventProperty Get(object index);
    [DispId(-4)]
    IEnumerator GetEnumerator();
    }
    Maybe I’ve done something dumb but….

    Am I supposed to iterate through the EventProperties? How do I figure out which object (what object exactly) is the one I want?

    1. Hi Ed,

      Did you find the documentation of the API in the help file?
      The documenation of EventProperties at http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/eventproperties.html
      says:
      Get (object Index)
      EventProperty
      Read only
      Returns an EventProperty in the list, raising an error if Index is out of range.
      Parameters:
      • Index: Variant – can either be a number representing a zero-based index into the array, or a string representing the name of the EventProperty; for example, Props.Get(3) or Props.Get(“ObjectID”)

      So of you need the ElementID I guess you should use the Get operation with parameter “ElementID” (or is it ObjectID as in the example from the help file?)

      You can either do that, or indeed iterate the EventProperties and check the name of each property until you find what you need. (which I guess the Get() operation is doing.)

      1. Thanks. Yes, I did fing the documentation later, and figured out what it meant. I was thrown off by the way the event function call documentation was written.

        It’s too bad that none of the code examples show the use of the EventProperties.

        What I’m struggling to figure out now is how to detect when an element is moved on a diagram and to where. From reading other forum entries I suspect this may not be easy. I suspect that EA_OnNotifyContextItemModified is the most promising, but we’ll find out.

  2. Ed Bridge :

    Thanks. Yes, I did fing the documentation later, and figured out what it meant. I was thrown off by the way the event function call documentation was written.

    It’s too bad that none of the code examples show the use of the EventProperties.

    What I’m struggling to figure out now is how to detect when an element is moved on a diagram and to where. From reading other forum entries I suspect this may not be easy. I suspect that EA_OnNotifyContextItemModified is the most promising, but we’ll find out.

    I’m not sure it that is even possible.
    The problem is that EA keeps layout changes to a diagram in its cache and only writes it to the database when the diagram is saved.
    From your add-in you don’t have access to this cached diagram, you can only retrieve the info from the database.

    So if you really need to know when an object has been moved on a diagram, you’ll have to record the location of each element when opening the diagram with EA_OnPostOpenDiagram, and compare that to the position of each element when you close the diagram using EA_OnPostCloseDiagram.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.