Book a Demo

Author Topic: how to get the element connected to a UseCase in a Diagram  (Read 9313 times)

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
how to get the element connected to a UseCase in a Diagram
« on: June 30, 2017, 09:50:32 pm »
Started to build a Script in Jscript to get all objects from a diagram, but i have no guarantee that the object is connected to the useCase.
How to get all objects connected to a usecase?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #1 on: June 30, 2017, 09:56:44 pm »
Retrieve the element from the ElementID (using Repository.GetElementByID) and look up the element's Connectors collection.

q.

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #2 on: June 30, 2017, 10:00:38 pm »
u can show a simple code, to undertand this

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #3 on: June 30, 2017, 10:03:43 pm »
I don't speak JScript. Look into the example scripts provided by Sparx to get an idea how to achieve that.

q.

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #4 on: June 30, 2017, 10:22:42 pm »
in javascript?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #5 on: June 30, 2017, 11:32:37 pm »
i no js no java no eql

stand
------
u

?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: how to get the element connected to a UseCase in a Diagram
« Reply #6 on: July 01, 2017, 05:01:58 pm »
Andrev,

You will have to show some more effort from your side then only send me teh codez

For your information I have a open source library with hundreds of VBScripts on github: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library
and an even bigger library of C# code dealing with EA
- https://github.com/GeertBellekens/Enterprise-Architect-Toolpack
- https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework
- https://github.com/GeertBellekens/UML-Tooling-Framework

This is full with examples on how to use the EA API, but you will have to do the search and translate work yourself.

Geert

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #7 on: July 04, 2017, 09:20:19 pm »
Sorry geert, idk how to get the connector informations, i just wat a example, note the whole code... I'm sorry if it just seemed like I just wanted you to do my job.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #8 on: July 04, 2017, 09:24:59 pm »
As I told you on StackOverflow: RTFM. This is not a tutorial place. Put in some effort to solve that yourself. If you then get stuck: ask.

q.

andrev

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #9 on: July 04, 2017, 09:36:14 pm »
my effort is this script tha gets all usecases and requeriments from a useCase Diagram http://imgur.com/a/QPbXN
But the order it gets is wrong,im my script, the order is:
requeriment: DOTZ
UseCase: uc7210
UseCase: uc 7172
Requeriment: crediário
Requeriment: débito

the second use case returns correct, but not the first..

this is my code:

Code: [Select]
function main()
{

var CSV_DELIMITER = ";";

var filePath = OpenCSVFileDialog();

//abort if no file was specified
if ( filePath == null || filePath == "" )
return;
Repository.EnsureOutputVisible("Script");
Repository.ClearOutput("Script");

Session.Output("Exportando diagrama para: " + filePath);

var exportFile; // : FileSystemObject
var exportColumns;
var exportIsExporting = false;
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();// collect the actual diagram

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

var columns = new Array("Caso de Uso","Descrição","Produtos"); // array with columns names

var fsObject = new ActiveXObject( "Scripting.FileSystemObject" );
var exportFile = fsObject.CreateTextFile( filePath, true );

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

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

exportFile.WriteLine( headingString );


var rowString = "";
for (var i = 0 ; i < dObjs.Count ; i++)
{
  // current diagram object
var dObj = dObjs.GetAt(i);
  var obj = Repository.GetElementByID  (dObj.ElementID); // related element
  rowString = "";
Session.Output("tipo" + obj.Type );
if (obj.Type == "UseCase" || obj.Type == "Requirement"){ //only want UCs
if(obj.Type == "Requirement")
rowString += CSV_DELIMITER + CSV_DELIMITER +obj.name;
else
rowString += obj.Name + CSV_DELIMITER + obj.Notes ;
     
var linha  = rowString.trim();
Session.Output(linha);
        exportFile.WriteLine( linha );
}
 


}


// Clean up file object and column array
exportFile.Close();
exportFile = null;
exportColumns = null;
Session.Output("Diagrama exportado para: " + filePath);
}
// remove spaces like function TRIM in Javascript
String.prototype.trim = function () {
    return this.rTrim().lTrim();
}
String.prototype.lTrim = function () {
    var whitespace = new RegExp("^\\s+","gm");
    return this.replace(whitespace, "");
}

String.prototype.rTrim = function () {
    var whitespace = new RegExp("\\s+$","gm");
    return this.replace(whitespace, "");
}


// open the dialog window to choose the save path
function OpenCSVFileDialog()
{
var Project;
var Filename, FilterString, Filterindex, Flags, InitialDirectory, OpenorSave, filepath;

Filename = "";
FilterString = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*||";
Filterindex = 1;
Flags = 0;
InitialDirectory = "";
OpenorSave = 1;

Project = Repository.GetProjectInterface();
filepath = Project.GetFileNameDialog(Filename, FilterString, Filterindex, Flags, InitialDirectory, OpenorSave);

return filepath;
}
main();

Because of that I was thinking of looking for the connectors, but i idk how to use get the connectors...

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #10 on: July 04, 2017, 09:50:13 pm »
Well, that's "some code" but none related to your original question.

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: how to get the element connected to a UseCase in a Diagram
« Reply #11 on: July 05, 2017, 12:21:49 pm »
But the order it gets is wrong

What order were you expecting? Looping the DiagramObjects collection will give you a collection of all objects on the diagram, but not in any particular order. If you need them in a specific order you may need to do some further processing.