Book a Demo

Author Topic: Load project to EA application  (Read 4619 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Load project to EA application
« on: September 01, 2014, 10:43:42 pm »
I would like EA to be opened programmatically.

The following code opens EA application, but no model is loaded.

Code: [Select]
ProcessStartInfo processInfo = new ProcessStartInfo(@"C:\Program Files\Sparx Systems\EA\EA.exe");
processInfo.Verb = "runas";
Process.Start(processInfo);

Is it possible?
Thanks in advance!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Load project to EA application
« Reply #1 on: September 01, 2014, 11:15:22 pm »
You need to call Repository.OpenFile

q.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Load project to EA application
« Reply #2 on: September 01, 2014, 11:39:32 pm »
qwerty's response is correct, but assumes that you're working with the EA API (so that you have access to the Repository class).

If all you want to do is fire up EA and open a specific project, but not interact with it programmatically, you should be able to do that by adding the path to the project as a command-line argument to the ProcessStartInfo constructor:

Code: [Select]
ProcessStartInfo processInfo =
    new ProcessStartInfo(@"C:\Program Files\Sparx Systems\EA\EA.exe",
                         @"Z:\EA\MyEaProject.EAP");

Of course, you shouldn't assume the EA executable is in this location; the user could have installed it somewhere else and even if it's in the default location this code won't work on a 64-bit Windows installation.

Instead, use the path stored in the registry under HKCU\Software\Sparx Systems\EA400\EA\Install Path.


/Uffe
« Last Edit: September 01, 2014, 11:44:00 pm by Uffe »
My theories are always correct, just apply them to the right reality.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Load project to EA application
« Reply #3 on: September 02, 2014, 06:55:31 pm »
Thank you qwerty and Uffe for the answers. Work great!

As Uffe suggested, the EA application path is retrieved from the registry in this way:

Code: [Select]
RegistryKey currentUserRegistryKey = Registry.CurrentUser;
const string eaSubkey = @"Software\Sparx Systems\EA400\EA";
RegistryKey eaRegistryKey = currentUserRegistryKey.OpenSubKey(eaSubkey);

if (eaRegistryKey != null)
    {
      //Retrieve the content of Install Path value.
      //The string "not exist" is returned and inserted into the string 'eaInstallationPath' in case there is no 'Install Path' value.
      string eaInstallationPath = (Registry.GetValue(eaRegistryKey.Name, "Install Path", "not exist")).ToString();

      if (eaInstallationPath.CompareTo("not exist") != 0)
        {
         ProcessStartInfo processInfo = new ProcessStartInfo(eaInstallationPath  + @".exe",  
                  @"Z:\EA\MyEaProject.EAP");
         processInfo.Verb = "runas";
         Process.Start(processInfo);
        }
     }

There is also the Project.LoadProhect() method.
« Last Edit: September 02, 2014, 06:57:27 pm by avoda234 »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Load project to EA application
« Reply #4 on: September 02, 2014, 07:41:17 pm »
No problem, and thanks for taking the time to share the working solution.

/U
My theories are always correct, just apply them to the right reality.