Book a Demo

Author Topic: Calling another Addin from Addin  (Read 7082 times)

ninew

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Calling another Addin from Addin
« on: September 25, 2018, 03:16:27 am »
I'm new to scripting with ea and tried to gather some infos about the accessable parts. Is there a way to access (public) functions of one addin inside of another addin? Is there a way to raise an EA_MenuClick signal to trigger an addin? It should work to programmatically select items (elements) inside of the project browser. But can i then also call an addin on them (through the menu)?

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Calling another Addin from Addin
« Reply #1 on: September 25, 2018, 05:25:24 am »
Hi

In response to your queries - this is my understanding (mainly based on some experiments I did a few years ago.  I wrote up in 6 or 7 blogs posts starting with Customising EA, in particular see Calling a running AddIn from a script which was looking at call an AddIn from a script (which could similarly be another AddIn). Another caveat- I assume normally programming and not poking around in system tables to look for entry points, etc!

Is there a way to access (public) functions of one addin inside of another addin?
Yes if you consider your other AddIn is only DLL that can be called and access any public method; HOWEVER this would be as a DLL within the context of the calling AddIn and NOT within the context of EA and an instance of the DLL that it could load separately and which would have its own state other actions resulting from calls from EA to that AddIn. 
CORRECTION: Further to Geerts comments I was curious so rerun some tests and it now looks like EA only loads a single instance of an AddIn DLL. Therefore when creating an instance of a class in the other AddIn it is using the same DLL instance.

FYI: My test consists of 2 addins.  The first has a menu option to call the 2nd and retrieve information (time of day, some counters and context for currently selected item), the 2nd AddIn has a menu option to allow me increase the counters.


Is there a way to raise an EA_MenuClick signal to trigger an addin?
No, this is an EA event and cannot be initiated from an AddIn action

can i then also call an addin on them (through the menu)?
You can dynamically provide AddIn menu options.

However, it would be useful to get a better idea of what you are want to do rather than assume it has to be multiple AddIns as there is probably a way to design an AddIn that would fulfill your needs.

Hope this helps.
Adrian


« Last Edit: September 25, 2018, 08:40:34 pm by EXploringEA »
EXploringEA - information, utilities and addins

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Calling another Addin from Addin
« Reply #2 on: September 25, 2018, 03:39:56 pm »
Yes you can execute public operations on an installed add-in. That is precisely what EA is doing.

I actually starting writing an add-in manager a few years ago.

The idea was to only install one add-in, and dynamically load and call the other add-ins from this add-in.
So when EA triggers an event, this add-in was to forward the event to all add-ins that had implemented the corresponding operation.

I never finished the project, but the code is still available on github: https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/tree/master/EAAddinManager

Geert

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Calling another Addin from Addin
« Reply #3 on: September 25, 2018, 04:43:39 pm »
@Geert -
Quote
Yes you can execute public operations on an installed add-in. That is precisely what EA is doing.

When I did my tests (albeit a while ago now) I found that the calling an AddIn from an AddIn loaded a separate instance of the DLL, hence state information (for the EA called AddIn) wasn't present.  Are you saying you could access the instance of the DLL that EA has loaded? I am interested to know more about this please.[/s]

CORRECTION: It has changed and as Geert explains you can create an instance of a class contained within another loaded AddIn and call its public methods.  That will teach me to rely on old (clearly out of date) tests :o

Of course, your approach using an AddIn manager would work as the DLLs would be loaded by the AddIn manager and hence within the same context.


Thanks
Adrian


« Last Edit: September 25, 2018, 08:44:18 pm by EXploringEA »
EXploringEA - information, utilities and addins

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Calling another Addin from Addin
« Reply #4 on: September 25, 2018, 08:45:53 pm »
Hi Adrian,

In my setup the add-in manager EA was only aware of one add-in (the addin-manager) and all additional addins were loaded from there, so I did not really have that issue.
I would guess that accessing an instance of an add-in class created by EA would be impossible, but I never really tried that.

Geert

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Calling another Addin from Addin
« Reply #5 on: September 25, 2018, 09:29:24 pm »
Hi Geert

Thanks for the info.  As you can see from my comments above there seem to have been some changes, not surprising it was 2014 when I did my previous tests, and it appears to work fine - to my surprise.

It is a simple test that has 2 addins both know to EA, and with AddIn1 having a reference to the DLL of AddIn2 to allow it to build.
To check operation and ability to get state information:
* AddIn1 - creates an instance of the AddIn2 class and calls a method to retrieve information from AddIn2
* AddIn2 - via an EA menu or context change (events used for checking) will update some static variables which are then used as part of providing the information to AddIn1.

I am sure that there are some other test cases that should be run.

BR
Adrian
PS: Sorry for any confusion caused.
 


EXploringEA - information, utilities and addins