Enterprise Architect Add-in, how to display log message

34 Views Asked by At

I'm writing a .NET add-in for Sparx Enterprise Architect and wish to log messages to the 'System Output' window or the add-in window.

What I tried:
The Console.Write and Trace.Write methods don't display in the EA gui. EA scripting allows writing messages through the Session.Output(...) method but the Interop.EA.dll doesn't seem to expose the Session interface. Popping up a message box with custom text works but doesn't suit displaying log messages.

One reason for displaying a running log this is to show progress and warnings to the user. So as a fall-back solution, I would be happy to display a progress bar or even an hourglass.

2

There are 2 best solutions below

0
Geert Bellekens On

You have to use EA.Repository.WriteOutput()

See https://www.sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/repository3.html for the documentation of that method.

Before you do, you might want to create the tab, clear it, and make it visible.

EA.Repository.CreateOutputTab()
EA.Repository.ClearOutput()
EA.Repository.EnsureOutputVisible()
0
sixdiamants On

Thanks to Geert's answer, here's a piece of code that tests logging. I commonly run and test code in LINQPad before putting it into production. This does the trick:

int pid = Process.GetProcessesByName("EA").First().Id;
var repo = SparxSystems.Services.GetRepository(pid);

const string logwindowName = "juridical logger";
repo.CreateOutputTab(logwindowName);
repo.ClearOutput(logwindowName);
repo.EnsureOutputVisible(logwindowName);
repo.WriteOutput(logwindowName, "ignorantia juris non excusat", 0);

A screenshot with LINQPad and EA in the background to prove the point:

enter image description here