byandreee byandreee - 7 months ago 52
Javascript Question

Export to Excel from a Diagram Enterprise Architect

I'm starting to work with Enterprise Architect and I need to make a script to export all use cases and notes, from a diagram to Excel.
However, the provided CSV export only works for packages, not for diagrams like this:

enter image description here

If I use the option "view as list", the diagram will show all use cases.
I need something like that, but with Notes, and exported to CSV/Excel.

enter image description here

Answer Source

The only thing you need to do is to relate the export script to the diagram in question. The easiest would be to access the diagram with

var dia = Repository.GetCurrentDiagram();

which returns the object for the currently open diagram.

The next is to scan the diagram objects and finding the use cases:

var dObjs = dia.DiagramObjects; // collection of diagram objects
for (var i = 0 ; i < dObjs.Count ; i++) {
  var dObj = dObjs.GetAt(i); // current diagram object
  var obj = Repository.GetElementByID (dObj).ElementID; // related element
  if (obj.Type == "UseCase") { // only interested in UCs
// this is a UC to export; do the magic here

Please note that the above was just written out of my head and might have syntax errors. But basically that's the way to go.

N.B.: The required csv export is easiest accomplished by using EAScriptLib's JScript-CSV.