Book a Demo

Author Topic: export a diagram Use-case to excel  (Read 7606 times)

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
export a diagram Use-case to excel
« on: June 22, 2017, 03:46:50 am »
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:


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.


my code is this:
Code: [Select]
!INC EAScriptLib.JScript-DateTime
!INC EAScriptLib.JScript-Logging

Repository.EnsureOutputVisible( "Script" );
Repository.ClearOutput("Script");



function main()
{
var CSV_DELIMITER = ",";
var CSV_final;
var exportFile; // : FileSystemObject

var exportIsExporting = false;

var currentDiagram as EA.Diagram; // collect the actual diagram

var dObjs = currentDiagram.DiagramObjects; // collection of diagram objects

var fileName = "/desktop/teste.csv"; // path to save de csv file

var columns = new Array("Caso de Uso","Descricao"); // array with columns names


var exportFile = fsObject.CreateTextFile( fileName, true );

// Export column headings if the option was enabled
var headingString = "";

for ( var i = 0 ; i < columns.length ; i++ )
{
if ( i == 0 )
headingString += columns[i];
else
headingString += CSV_DELIMITER + columns[i];
}

exportFile.WriteLine( headingString );

var rowString = "";
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 want UCs
  rowString += __CSVEToSafeCSVString(dObj.Name) + CSV_DELIMITER + __CSVEToSafeCSVString(dObj.Notes);
 
  exportFile.WriteLine( rowString );
}


// Clean up file object and column array
exportFile.Close();
exportFile = null;
exportColumns = null;

// Switch out of exporting mode
exportIsExporting = false;


}

function __CSVEToSafeCSVString( originalString /* : String */ ) /* : String */
{
var returnString = new String(originalString);

// Strip out delimiters
var delimiterRegExp = new RegExp( CSV_DELIMITER, "gm" );
returnString = returnString.replace( delimiterRegExp, "" );

// Strip out newline chars
var newlineRegExp = new RegExp( "\r\n?", "gm" );
returnString = returnString.replace( newlineRegExp, " " );

return returnString;
}


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: export a diagram Use-case to excel
« Reply #1 on: June 22, 2017, 08:56:16 am »
So, what is the issue?

q.

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: export a diagram Use-case to excel
« Reply #2 on: June 22, 2017, 11:17:42 pm »
Im sorry, the problem is, i cant get the diagram, var currentDiagram as EA.Diagram return nothing

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: export a diagram Use-case to excel
« Reply #3 on: June 22, 2017, 11:19:34 pm »
As I wrote in my SO answer you need to call
Code: [Select]
Repository.GetCurrentDiagram()to access the currently open diagram.

q.

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: export a diagram Use-case to excel
« Reply #4 on: June 22, 2017, 11:31:44 pm »
now at this point, gives me incompatible type
Code: [Select]
var obj = Repository.GetElementByID  (dObj).ElementID; // related element
« Last Edit: June 22, 2017, 11:38:12 pm by andrev »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: export a diagram Use-case to excel
« Reply #5 on: June 23, 2017, 05:12:32 am »
Your brackets are wrong. Use
Code: [Select]
var obj = Repository.GetElementByID  (dObj.ElementID); // related element
q.