byandreee byandreee - 9 months ago 29
Javascript Question

Export to Excel from a Diagram UseCase Enterprise Architect

IM starting working with Enterprise Architect and my boss asked me to make a script/template to export all use cases and notes, from a diagram to excel,
but with CSV export, he brings only useCases in a determined package, but we had a reuse UseCase, that is imported from another project.

Use Case Diagram

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 in excel
View Diagram as list

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download