Author Topic: Call Addin from JavaScript  (Read 8325 times)

whitehouse

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Call Addin from JavaScript
« on: July 17, 2015, 07:14:19 pm »
Hello, I would need some help.

I have my own Add in with class:

Code: [Select]
namespace MyAddIn
{
    public static class RepositoryExtensions
    {

        public static string someMethod(string input)
        {
            return "Hello" + input;
        }
      }
}
Is there any way to invoke my class from JavaScript like that:
Code: [Select]
Session.Output( "JScript test API");
      var msg = MyAddIn.RepositoryExtensions.someMethod("aaaaaa");
      Session.Output(msg);

BR.
« Last Edit: July 17, 2015, 07:15:15 pm by whitehouse »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #1 on: July 19, 2015, 07:46:27 pm »
Hi,

All depends if you want to call the running Addin and access current objects or access a DLL that is not "connected" to the running instance of EA.  The problem is finding the relevant reference to the addin DLL.

If you create an object for your DLL there is no problem, however trying to get a reference to the EA "connected" copy proved problematic.

I wrote a post outlining my unsuccessful experiments
http://exploringea.com/2015/03/10/scripting-follow-up-on-case-7-can-a-script-call-a-running-ea-

Let us know if you find a reliable means to identify the addin object as I'm sure there are a few out there who would like to use it.


EXploringEA - information, utilities and addins

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #2 on: July 24, 2015, 08:21:24 pm »
Hi guys,
Any progress in calling add-ins from JScript or VBScript?
I've read the article mentioned above. Too complicated. Looks like there should be some easy way just like in Shape Script where one can read some values calling add-in's functions with parameters using some special syntax.
But I haven't found it, yet.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8064
  • Karma: +118/-20
    • View Profile
Re: Call Addin from JavaScript
« Reply #3 on: July 27, 2015, 08:43:08 am »
Quote
Looks like there should be some easy way
If there is one, it wasn't written by Sparx Systems.

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #4 on: July 27, 2015, 03:35:39 pm »
Well Simon, looks like. Yes. But should be. Many tasks can involve cross-level interaction. And I'd prefer to have some 'gate' between scripting and add-ins layers. Really useful

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8064
  • Karma: +118/-20
    • View Profile
Re: Call Addin from JavaScript
« Reply #5 on: July 27, 2015, 05:12:29 pm »
I don't doubt that there are use cases where it would be useful. That doesn't mean that it "should" be done.

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #6 on: July 27, 2015, 05:48:21 pm »
Let's vote for new feature?  ;)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Call Addin from JavaScript
« Reply #7 on: July 27, 2015, 08:01:37 pm »
I guess this vote is like that for the Volkskammer. So except you know Erich in person your vote would be as futile as that of any other socialist. Or as skiwi puts it: send a feature request. Have your friends send it too and their friends and friends of friends. And if you happen to know some trainers... You know the game.

q.

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #8 on: July 27, 2015, 08:19:15 pm »
You're right absolutely! I'll be trying to organize that kinda 'waterfall' :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Call Addin from JavaScript
« Reply #9 on: August 04, 2015, 05:03:09 pm »
Quote
Hi,

All depends if you want to call the running Addin and access current objects or access a DLL that is not "connected" to the running instance of EA.  The problem is finding the relevant reference to the addin DLL.

If you create an object for your DLL there is no problem, however trying to get a reference to the EA "connected" copy proved problematic.

I wrote a post outlining my unsuccessful experiments
http://exploringea.com/2015/03/10/scripting-follow-up-on-case-7-can-a-script-call-a-running-ea-

Let us know if you find a reliable means to identify the addin object as I'm sure there are a few out there who would like to use it.



I'm working on an add-in that loads (and executes) other add-ins.
I still have to polish it up and make it user friendly and configurable, but the basic version already works.
The code is available on github: https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/tree/master/EAAddinManager

So Yes it is possible to execute operations from add-ins, and it can probably be done from the scripting environment as well.

No, it's not easy I'm afraid :-/

Geert

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #10 on: August 04, 2015, 05:13:46 pm »
Hi Geert,
Waiting for impatiently!!
 :D

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #11 on: August 07, 2015, 06:36:45 pm »
Hi Geert

I must admit I haven't looked at your code, which probably has the answer, but interested to know the approach to getting the reference to the addin as this was the problem found before when working within the scripting thread.

Is your approach to launch the addin from the scripting environment?

I will look at the code when I get time - but curious to know!

Tnx
EXploringEA - information, utilities and addins

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Call Addin from JavaScript
« Reply #12 on: August 07, 2015, 08:41:46 pm »
From my add-in (not scripting) I load the add-ins myself.
The only add-in that is loaded as far as EA is concerned is my AddinManager addin.

And since I load the add-ins I don't have the problem of getting the reference.

I guess loading an add-in from the scripting environment isn't that difficult.
Your problem was more how to access an already running addin instance I guess?

It feels to my like that should be possible as well. You can get a reference to the running instance of EA, isn't it possible to use that same mechanism to access the running instance of an add-in?

On the other had, the need to access the running instance only appears when you have some state in the add-in that you need to use.
If you have a stateless add-in then it wouldn't matter if the scripting environment started a new instance or accesses the running instance.

Geert

whitehouse

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #13 on: August 11, 2015, 02:11:50 pm »
 1 vote for new feature.  :).

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Call Addin from JavaScript
« Reply #14 on: August 11, 2015, 08:55:23 pm »
@Geert

yes loading an AddIN (i.e. a DLL) is straightforward from scripting - yes the problem is accessing the already running DLL.  My initial tests, some months ago now, didn't succeed and I have the idea of doing some more.  As you say it should be possible as it's only finding the correct table entry in the windows OS and when I get some time I hope to sort it out - perhaps the Christmas holidays!!

However, if you are not worried about state then you could load the addin as a new instance, and I guess if you wanted to respond to EA AddIn events that's where EA-Matic could come into it's own - is it realistic for it to capture and pass on all events that are configured?  Seems a genius idea.



EXploringEA - information, utilities and addins