Override EA add-in event

The complete Enterprise Architect C# add-in template

Using the complete Enterprise Architect C# add-in template will help you speed up the process of writing add-ins for Sparx Enterprise Architect

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
namespace NewAddin
{
    public class AddinClass: EAAddinFramework.EAAddinBase
    {
  • 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.

More resources

Related articles

Source code on Github

Sparx Systems

Other

8 replies
  1. Ed Bridge
    Ed Bridge says:

    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?

    Reply
    • geertbellekens
      geertbellekens says:

      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.)

      Reply
      • Ed Bridge
        Ed Bridge says:

        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.

        Reply
  2. geertbellekens
    geertbellekens says:

    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.

    Reply

Trackbacks & Pingbacks

  1. […] The complete Enterprise Architect C# add-in template Making your life easier with the add-in template […]

  2. […] posts I talked about Creating and Testing your Enterprise Architect C# add-in, and how to use the C# add-in template to speed up the development […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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