Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Knut Paulsen on November 05, 2014, 11:36:41 pm
-
Hi guys,
I want to find and access instances of EA already running on my computer. Using Microsoft.VisualBasic.Interaction.GetObject (from C#), I get one instance and it appears to be the 'oldest' one.
Any suggestion how I can find them all, and get hold of the repository object?
cheers
Knut
-
You will likely have better chances if you ask this question at StackExchange.
To get the repository object of the instance just use this:Dim Repository As EA.repository
Set EAapp = GetObject(, "EA.App")
Set Repository = EAapp.repository
(from my Scripting book)
q.
-
To get all instances EA you can use the windows GetProcessByName method on the process class from which you can check
For Each proc As Process In Process.GetProcessesByName("EA")
' processing....
' e.g. you can then get process information e.g. starttime of process
startTime = proc.StartTime
Next proc
May be worth downloading a copy of procexp within the systems internals suite (now within ms http://technet.microsoft.com/en-gb/sysinternals/bb545021.aspx ), if need to explore details of processes further.
Hope that helps.
-
Hi Knut,
I have this code in my EA Repository wrapper Model.cs (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/Model.cs) which uses System.Diagnostics.Process.GetProcesses() to find all EA instances.
/// <summary>
/// the main EA window to use when opening properties dialogs
/// </summary>
public IWin32Window mainEAWindow
{
get
{
if //(true)
(this._mainEAWindow == null)
{
List<Process> allProcesses = new List<Process>( Process.GetProcesses());
Process proc = allProcesses.Find(pr => pr.ProcessName == "EA");
//if we don't find the process then we set the mainwindow to null
if (proc == null
|| proc.MainWindowHandle == null)
{
this._mainEAWindow = null;
}
else
{
//found it. Create new WindowWrapper
this._mainEAWindow = new WindowWrapper(proc.MainWindowHandle);
}
}
return this._mainEAWindow;
}
}
The proper way of connecting the the (oldest) EA instance in C# is using System.Runtime.InteropServices.Marshal.GetActiveObject() like this:
/// Creates a model connecting to the first running instance of EA
public Model(){
object obj = Marshal.GetActiveObject("EA.App");
global::EA.App eaApp = obj as global::EA.App;
wrappedModel = eaApp.Repository;
}
Regards
Geert
-
Thanks guys, interesting :-)
Gert: let's say I have three EA.exe processes running and you find them via the allProcesses list. Is it then possible to access the EA repository object in all three processes? I could not quite see the connection between _mainEAWindow and the EA.Repository from your code sample.
Cheers
Knut
-
Imagine those instances as 3 independent users. It behaves the same. If you don't have locking you have a "first come, last served" behavior. IOW: the person clicking save at last will make the permanent changes. Eventually you'll see "underlying model has been changed".
q.
-
Thanks guys, interesting :-)
Gert: let's say I have three EA.exe processes running and you find them via the allProcesses list. Is it then possible to access the EA repository object in all three processes? I could not quite see the connection between _mainEAWindow and the EA.Repository from your code sample.
Cheers
Knut
I guess it should be possible, but I haven't tried.
I would start by reading the documentation on the Marshal object and its methods
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getactiveobject(v=vs.100).aspx
Geert