Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: waheedmp3 on May 31, 2016, 10:36:48 pm
-
I need to access the running instance of EA from C#,
I have two machines one with EA version 10 installed and the other has version 12
The following code snippet works fine and returns the correct connection string with EA Version 10
EA.App EAApplication = (EA.App)Marshal.GetActiveObject("EA.App");
string connStr = EAApplication.Repository.ConnectionString;
Collection models = EAApplication.Repository.Models;
but with EA version 12 ConnectionString is empty and it throws an exception that a file must be open before accessing the repository members.
-
Hello,
That GetObj() looks suspicious to me.
The Windows API call is GetObject(), so GetObj() looks like a wrapper of some sort. Are you sure you've got that in scope in both environments?
And I know this is an is-it-plugged-in type question, but are you sure your EA 12 instance actually has a repository open?
Finally, unless this is a throwaway hack, this design won't work because there is no "the running instance" of EA. You can run as many instances of EA as you've got memory for, and you can even connect to the same repository in different instances on the same machine.
/Uffe
-
Hello,
That GetObj() looks suspicious to me.
The Windows API call is GetObject(), so GetObj() looks like a wrapper of some sort. Are you sure you've got that in scope in both environments?
And I know this is an is-it-plugged-in type question, but are you sure your EA 12 instance actually has a repository open?
Finally, unless this is a throwaway hack, this design won't work because there is no "the running instance" of EA. You can run as many instances of EA as you've got memory for, and you can even connect to the same repository in different instances on the same machine.
/Uffe
That was a typo mistake, I actually use "Marshal.GetActiveObject"
-
Hi again,
If you can access Repository.ConnectionString but not Repository.Models that must mean you get hold of an EA.App object, ie a running instance, but one which does not have an open repository.
You should check that there aren't any other EA instances running than the one you expect. Maybe you've created one in a script somewhere that's been left dangling?
/Uffe
-
Hi again,
If you can access Repository.ConnectionString but not Repository.Models that must mean you get hold of an EA.App object, ie a running instance, but one which does not have an open repository.
You should check that there aren't any other EA instances running than the one you expect. Maybe you've created one in a script somewhere that's been left dangling?
/Uffe
You are right, there was many instances of EA in the background, I ran the taskkill command and started only one instance then it worked.
Thank you.
-
In general the GetActiveObject will connect tot the instance of EA that has first been started up.
But indeed, and especially when debugging add-ins you can have lingering ghost ea.exe processes in the background.
Geert