A running instance of EA can be accessed from a Python script with something like:
from win32com import client eaApp = client.GetActiveObject("EA.App") eaRepo = eaApp.Repository
However, this seems to always returns the COM object of the instance first started.
Let’s say we have a script that needs to starts a new instance of EA. It does so by calling os.startfile(eapxFile)
with eapxFile
being the path to an empty EA file. Then it should import some XMI file, for which it needs access to the COM object.
At the same time, a couple of other (older) instances of EA are open. How can the COM object of the new instance of EA be retrieved?
Note: An alternative way of starting a new instance of EA, if immediate access to its COM object is possible, would of course be feasible as well. Maybe even using the COM interface directly. Most importantly, other running instances of EA can not be used.
Advertisement
Answer
In VBScript you can create an EA.Repository
object in a brand new EA instance using
dim repository set repository = CreateObject("EA.Repository")
The Python equivalent seems to be
from comtypes.client import CreateObject repository = CreateObject("EA.Repository")
then open a model using
repository.OpenFile(myEapFile)
close the model using
repository.CloseFile()
followed by
repository.Exit()
to make sure the instance of the ea.exe process is closed.