Author Topic: Control EA via command line  (Read 23449 times)

bergst

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Control EA via command line
« on: January 23, 2018, 09:03:54 pm »
Hi everybody,

is it possible to control enterpirse architect via command line and is there any documenation about this topic?

What i want to do:
I use a diagram script to generate a rtf-Report. We want to automate this step and have it done by jenkins every night. I think it would work with EA-Automation (like an external c#-code) but it would be nice if it would work with the already existing scripts of EA.

Thanks!

PeterHeintz

  • EA User
  • **
  • Posts: 967
  • Karma: +58/-18
    • View Profile
Re: Control EA via command line
« Reply #1 on: January 23, 2018, 09:13:12 pm »
Hi,
we use e.g. PowerShell to do such kind of things.
Here is a PowerShell fragment transferring a repository to some other place, just to give yoiu an idea.

 $ea = new-object -ComObject "EA.Repository" -ErrorAction Stop #-Strict
 $eaProject = $ea.GetProjectInterface()  #-ErrorAction Stop
 $bTransferOk = $eaProject.ProjectTransfer($sourceRepository, $UpdatePath, $logFile)  #-ErrorAction Stop
 Start-Sleep 5; # -ErrorAction Stop
 $ea.Exit();  #-ErrorAction Stop
Best regards,

Peter Heintz

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Control EA via command line
« Reply #2 on: January 23, 2018, 09:42:53 pm »
is it possible to control enterpirse architect via command line and is there any documenation about this topic?
Yes and no, in that order. There's nothing in the official documentation, but with Peter's approach you can do everything the "Object Model" API allows.

Quote
What i want to do:
I use a diagram script to generate a rtf-Report. We want to automate this step and have it done by jenkins every night. I think it would work with EA-Automation (like an external c#-code) but it would be nice if it would work with the already existing scripts of EA.
You can't invoke scripts through the API so you'd essentially have to reimplement the document generation script in your PowerShell script. But that shouldn't be too hard, since the in-EA script is using that very same API in the first place (meaning it can't do anything your PowerShell script couldn't).

As far as running at night, however, you'll hit the snag every automator does: EA has to be run in a logged-in user session. This applies to the automation API as well: it's client-side only, there is no server-side automation.

So you can schedule your script to run whenever you want, but you need to leave a logged-in computer on overnight for it to work. Whether that's something you can get Jenkins to do I don't know.

HTH,


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

bergst

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Control EA via command line
« Reply #3 on: January 23, 2018, 09:50:54 pm »
I will try to put the code of the EA-Script to an PowerShell script. I also will upload my solution if it works.

Thank you for your quick reply!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Control EA via command line
« Reply #4 on: January 23, 2018, 10:44:21 pm »
I will try to put the code of the EA-Script to an PowerShell script. I also will upload my solution if it works.

Thank you for your quick reply!
You can also use .vbs files and execute those. I have some clients who use that to create backups (model transfer) or a daily HTML export to Sharepoint.

The advantage of .vbs is that you can almost copy/paste existing scripts from EA.
You only need to create a Repository object, and make sure you're not using Session or "as EA.xxx" syntax.

Geert

PS. Although not supported by the API you can technically execute scripts stored in EA using MS Scriptcontroller. See https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EASpecific/Script.cs for a C# implementation.

bergst

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Control EA via command line
« Reply #5 on: January 25, 2018, 07:59:28 pm »
I figured out that i don´t like VBS so i decided to change to C#.

I got a quite simple solution to generate documents via c#.

Code: [Select]
//References: http://www.sparxsystems.com/enterprise_architect_user_guide/12.0/automation_and_scripting/reference.html

namespace CSharp_GenerateDoc
{
    class Program
    {
        static string File = Path to .eap-File;     
        static string GUID = GUID of required package;                      //GUID vom "Requirements" Package unter "Global"
        static string Doc_Template = Name of Document_Template;
        static string FileName = Name of generated File;

        static void Main(string[] args)                             
        {
            EA.App EAClient = new EA.App();                         
            EA.Repository EA_Repo = new EA.Repository();           
            EA.Project EA_Proj = new EA.Project();                 
            EA_Repo.OpenFile(File);
            EAClient.Visible = false;
            EA_Proj.RunReport(GUID, Dok_Template, FileName);
            EA_Repo.Exit();
        }

    }
}


Thanks for help!

priombiswas89

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: Control EA via command line
« Reply #6 on: June 02, 2021, 12:49:56 am »
I have developed a plugin which generates yaml representation of diagrams. I am searching for something similar, but for my case:

User will enter:
  • .eap file path
  • guid of diagram, path where yaml will be generated
  • path where yaml will be generated

from a c# console application. Enterprise architect will then be opened with the diagram file, run the yaml generator plugin, generate the yaml in the mentioned path, and close enterprise architect. Is there actually any way to do that automation?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Control EA via command line
« Reply #7 on: June 02, 2021, 03:41:06 am »
Sure, can definitely be done, more or less the same way as your example code.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Control EA via command line
« Reply #8 on: June 02, 2021, 06:50:00 am »
A strange use case, though. I regularly run scripts from outside EA. But more or less I have the application opened all day. Modeling is an active duty, not a self service where you throw in money to get out a can. At least that's what I think.

q.

priombiswas89

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: Control EA via command line
« Reply #9 on: June 02, 2021, 06:40:52 pm »
Sure, can definitely be done, more or less the same way as your example code.

Geert

As long as my knowledge from the documentations provided by EA, till now, I haven't found any api to call a specific addin and feed in the diagram guid.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Control EA via command line
« Reply #10 on: June 02, 2021, 06:51:49 pm »
No, you can't, but since you wrote the add-in, you can simply call the required operations can't you?

I've written a number of add-ins, and for some of them I also wrote a standalone program to call the add-in code.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Control EA via command line
« Reply #11 on: June 02, 2021, 08:32:00 pm »
Sure, this one for example.

https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/tree/master/EAMappingApp

I think it connects to the running instance of EA, but you can make it start up a new instance as well.

Geert

jörg

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Control EA via command line
« Reply #12 on: June 15, 2021, 11:49:25 pm »
I tried it in the way posted by bergst, unfortunately I get System.InvalidCastExceptions. When I call
Code: [Select]
App EAClient = new App(); an object of type EA.AppClass is created instead an object of type EA.App.  ???
It has 4 members: Project, Repository, Visible and WebServerPort. In the debugger each of them shows a message like
Quote
Project = '((EA.AppClass)EAClient).Project' threw an exception of type 'System.InvalidCastException'.
The same happens when creating the Repository object. The object is created, but all members show this message in the debugger. Of course, when I then call EARepo.OpenFile(EAProjectFile); an exception is thrown:
Quote
Unable to cast COM object of type 'EA.RepositoryClass' to interface type 'EA.IDualRepository'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{4CD2CE1E-C301-4C16-9CA2-5A7EC4478C55}' failed due to the following error: Schnittstelle nicht unterstützt (0x80004002 (E_NOINTERFACE)).

So something really goes wrong with the object creation. Please can someone give me a hint whats going on there? Why are there types mangeled?

@ Geert: In your project I coudn't find the appropriate code.

Jörg

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Control EA via command line
« Reply #13 on: June 16, 2021, 01:52:30 am »
According to the manual it should not be more than

Code: [Select]
      EA.Repository r = new EA.Repository();
      r.OpenFile("c:\\eatest.eap");

See https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/automation_connect_setup.html

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: Control EA via command line
« Reply #14 on: June 16, 2021, 09:31:19 am »
https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/app.html

Quote
The App object represents a running instance of Enterprise Architect. Its object provides access to the Automation Interface.

The equivalent in C# would call Marshal.GetActiveObject