Book a Demo

Author Topic: [RESOLVED] Open Active Model From External Code  (Read 6309 times)

ToddO

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
[RESOLVED] Open Active Model From External Code
« on: June 14, 2011, 08:26:34 pm »
Hi, forgive me if this has been asked before, I searched but couldn't find an answer.

I can open a repository file and iterate across model elements programmatically using the example code in the SDK documentation but is it possible to connect to a currently open model?
i.e. I open a repository so it is loaded in EA and then connect to that instance, rather than specifying a path to a project.

Any tips are much appreciated.
« Last Edit: June 14, 2011, 09:08:01 pm by ToddO »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Open Active Model From External Code
« Reply #1 on: June 14, 2011, 09:00:16 pm »
in C# it's like this:
Code: [Select]
       /// <summary>
        /// Gets the Repository object from the currently running instance of EA.
        /// If multiple instances are running it returns the first one opened.
        /// </summary>
        /// <returns>Repository object for the running instance of EA</returns>
        private static EA.Repository getOpenedModel()
        {
            try
            {
                
                return ((EA.App)Marshal.GetActiveObject("EA.App")).Repository;
                
            }
            catch (COMException )
            {
                DialogResult result = MessageBox.Show("Could not find running instance of EA.\nStart EA and try again"
                                   , "EA not running",MessageBoxButtons.RetryCancel,MessageBoxIcon.Warning);
                if (result == DialogResult.Retry)
                {
                    return getOpenedModel();
                }
                else
                {
                    return null;
                }
            }
        }

See https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinTester/EAAddinTesterProgram.cs for an example on how to use it

Geert

ToddO

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Open Active Model From External Code
« Reply #2 on: June 14, 2011, 09:06:43 pm »
Thanks Geert, will have a look and let you know if I have any more questions.