Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bergst 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!
-
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
-
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.
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
-
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!
-
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 (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EASpecific/Script.cs) for a C# implementation.
-
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#.
//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!
-
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?
-
Sure, can definitely be done, more or less the same way as your example code.
Geert
-
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.
-
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.
-
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
-
Sure, this one for example.
https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/tree/master/EAMappingApp (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
-
I tried it in the way posted by bergst, unfortunately I get System.InvalidCastExceptions. When I call
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 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: 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
-
According to the manual it should not be more than
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 (https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/automation_connect_setup.html)
Geert
-
https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/app.html (https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/app.html)
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 (https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getactiveobject?redirectedfrom=MSDN&view=netframework-4.8#System_Runtime_InteropServices_Marshal_GetActiveObject_System_String_)
-
https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/app.html (https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/app.html)
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 (https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getactiveobject?redirectedfrom=MSDN&view=netframework-4.8#System_Runtime_InteropServices_Marshal_GetActiveObject_System_String_)
Ok, but that is to connect to an already running instance isn't it?
I think Jörg wants to start a new instance of EA.
The code I copied came directly from the manual in the section C#. Is that not correct?
Geert
-
Thanks for the replies.
@Eve: I also tried this approach just for test, but the call to Marshal.GetActiveObject("EA.App") returned null. And yes, EA was running befor calling ;).
@ Geert: I've found this article while searching a solution, too. Unfortunately it doesn't work :( as described in my question.
There seems to be something wrong with the types. I have no clue why this happens and how to fix that. I tried the code in several VS-Projects, with different .NET Framework versions and .NET Core 3. Always the same result.
-
Is there no idea how to solve this?
In my Project I use .NET Framework 4.7.2 but I also tried it with .NET 5.0 and .NET Core 3.1 -> no success. According to the EA documentation it should be possible.
I need this for module testing of modules that need data from EA Repository (modules of an EA-AddIn). If someone has ideas how to test EA-AddIn modules in another way, I'm open to hear them.
-
You could use the Labnaf PowerShell (https://www.labnaf.one/EndUserMaterial/Labnaf_PowerShell/Labnaf%20PowerShell%20-%20User%20Guide.pdf)
The following features are independent of the modeling language:
Schedule Command (not only Labnaf PowerShell commands)
Generate Word, RTF, PDF (there are also templates provided)
Generate Html (with ability to start email discussion from any diagram on the generated web site)
Backup To Access File
The following features are designed for the unified Labnaf language
(unified language for driving transformations: https://www.labnaf.one/guidance/index.html?guid=D1744801-D8E6-4715-83DB-DED6C781B191):
Generate Tabular Report (sophisticated Excel, CSV) from modeled templates
Import Tabular Report (Excel, CSV)
Cascaded Value calculation
Validate and send emails to assigned individuals following configurable rules
Generate Diagrams from diagram templates
Generate implicit connectors
www.labnaf.one