4

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.

22
  • I don't get it. If you start a new instance, then you already have the COM object don't you? There would not be a need to get a specific running instance. Commented Nov 9, 2021 at 17:49
  • @GeertBellekens He wants to pick a certain instance from multiple running ones I guess. Personally I only deal with a single EA instance in all cases. Simple requirement for my scripts. Commented Nov 12, 2021 at 11:03
  • @GeertBellekens I started the new instance by calling the EA executable. Commented Nov 12, 2021 at 12:49
  • Basically if there is a way to get a COM object for a newly created instance of EA, that would be awesome. I tried using DispatchEx to get a 'new' COM object as mentioned here: stackoverflow.com/questions/18648933/… but that just seems to freeze my script. Commented Nov 12, 2021 at 13:04
  • 1
    @AnandSowmithiran That's exactly what not happens. Dispatch will eventually create an instance if there is none. But else it will return the already running one and not create a new one. Commented Nov 21, 2021 at 23:20

1 Answer 1

2
+100

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Cool stuff, I didn't know about the comtypes library. On playing around with that in the Python Console, I see CreateObject reliably gives me one new EA instance no matter how many other manually started EAs are already running. But once I start one EA instance with CreateObject, if I try to do it again I either get the same old one I started previously or the console/script simply freezes. Guessing this might be an issue on EAs side. Unfortunately, starting up several instances of EA by script is a use case for us...
I added another question to ask specifically for how to start a new EA through COM: stackoverflow.com/questions/70068010/… - can't really accept this as an answer for the question I posed. Feel free to put the answer there as well.
Verified that this is working :-)
@Benjamin4991 this new question is just the same as this one and Geert answered it well!
Actually, you're right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.