Book a Demo

Author Topic: Connect to currently running EA app - C#?  (Read 4367 times)

weasee

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Connect to currently running EA app - C#?
« on: December 08, 2012, 07:23:42 pm »
Hi,

I am using the automation interface to connect to EA and extract various pieces of information from the repository (using C#).

I would like to connect to the current instance: from reading the docs, I should just be able to do:
Code: [Select]
EA.App app = new EA.App();
 string cs = app.Repository.ConnectionString;

But cs is empty; if I call any methods on the repository it complains I haven't opened a file yet. It seems it hasn't connected to the current instance.

Any pointers?

Thanks,
Mike.

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Connect to currently running EA app - C#?
« Reply #1 on: December 08, 2012, 11:15:45 pm »
I guess its empty because you created a new instance of EA and haven't told EA which repository to open.

If EA is already running and connected to the repository, use GetObject("EA.App") to obtain a reference to it.

best regards,

Paulus

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Connect to currently running EA app - C#?
« Reply #2 on: December 10, 2012, 03:47:43 pm »
From Model.cs, a wrapper for EA.Repository

Code: [Select]
   /// 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;
    }

Geert