Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: jk on July 09, 2018, 04:53:15 pm

Title: C# addin - listing all objects inside a project
Post by: jk on July 09, 2018, 04:53:15 pm
Hello all,

After working sometimes with the C# Framework for Enterprise Architect, I want to be able to generate a table which lists all objects in the model and shows me, in how many reports (0; 1; >1) each object is used.

Is it possible to do this with the C# Framework to develop such a AddIn for EA? I have no idea how to do this.


Thanks in advance!

BR

Title: Re: C# addin - listing all objects inside a project
Post by: Dahsra on July 09, 2018, 05:00:03 pm
Hi JK

 Refer Recursive Model Dump Example script from EA Local Scripts .
You need to recursively iterate from the model.

This will list the entire model .



HTH
Arshad
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 09, 2018, 05:45:53 pm
Ah thank you!  :)

Is it possible to figure out which connectors are truly connected to other ports/or "hanging in the air"?
Based on the elementIDs it should be possible to find recursively the connection between them?

Thanks,


Title: Re: C# addin - listing all objects inside a project
Post by: Dahsra on July 09, 2018, 06:20:23 pm
Yes you can get the connectors information of an element in the Connector collection of element class.

Code: [Select]
foreach(EA.Connector con in theElement.Connectors)
{
//your code
}
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 09, 2018, 07:55:41 pm
Ah thank you!  :)

Is it possible to figure out which connectors are truly connected to other ports/or "hanging in the air"?
Based on the elementIDs it should be possible to find recursively the connection between them?

Thanks,
Connectors "hanging in the air" do not exist. A connector has always two ends.

q.
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 11, 2018, 05:44:23 pm
Hello together,

maybe I wrongly expressed me issue:
I want to be able to find all unconnected/not-connected ports within the overview of the EA model.
I would like to develop it in C# or Javascript (inside of Enterprise Architect).

Is there any way to do this?

Thanks a lot.
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 11, 2018, 08:40:39 pm
Yes. You can create a single query to return that. I'll have a look into that after lunch. (No promises, though)

q.
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 11, 2018, 08:42:51 pm
Oh thanks.

That would be nice!  :)  :)


I tried it, but it isnt working.



BR
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 11, 2018, 09:15:19 pm
Here it is:
Code: [Select]
select * from t_object where object_type = "Port" and (select count(*) from t_connector where t_connector.End_Object_ID = t_object.Object_ID) = 0
q.
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 11, 2018, 10:05:15 pm
Thank you, I will try it!  :)
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 11, 2018, 11:11:17 pm
I do not understand what  the System Output is printing.

Code: [Select]
Session.Output(Repository.SQLQuery("select * from t_object where object_type = 'Port' and (select count(*) from t_connector where t_connector.End_Object_ID = t_object.Object_ID) = 0"));

It looks like xml and brings "all" functions but not the name of the not-connected ports of the whole model. :(

What is wrong with my query? I added the line above in the EA javascript.

Thanks!
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 12, 2018, 12:19:14 am
Yes. If you read the documentation you find that the result of SQLQuery is XML. You might reduce it to just the Object_ID which you then can use to locate the elements with Repository.GetElementByID

q.
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 12, 2018, 04:03:34 pm
Hello,

now I added your example query into the function of the Script "RecursiveModel Dump Example" for testing:

Code: [Select]
function DumpElements( indent, thePackage )
{
// Cast thePackage to EA.Package so we get intellisense
var currentPackage as EA.Package;
currentPackage = thePackage;

// Iterate through all elements and add them to the list
var elementEnumerator = new Enumerator( currentPackage.Elements );


Session.Output(Repository.GetElementByID (Repository.SQLQuery("select * from t_object where object_type = 'Port' and (select count(*) from t_connector where t_connector.End_Object_ID = t_object.Object_ID) = 0")));



}


After clicking "Run script" in the EA Script-Editor, I get the error-message "SScripter.exe is not working - Close Program - Debug Program".
When I start "Run Debugging", then the script put out any outputs in the Debug window (e.g. "[1895347727]                  xyz (PackageID=3734)").

Why I get the SScripter.exe error message and why I do not get the respective ID of the "not-connected" ports?


Thanks!
Title: Re: C# addin - listing all objects inside a project
Post by: Dahsra on July 12, 2018, 04:49:38 pm
The entire piece of code wont work together in the way youve used .

To Use ElementSet
Code: [Select]
Repository.GetElementSet("select t_object.Object_ID from t_object where object_type = 'Port' and (select count(*) from t_connector where t_connector.End_Object_ID = t_object.Object_ID) = 0",2);
For More details on Repository.GetElementSet (https://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/repository3.html)

HTH
Arshad
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 12, 2018, 05:55:19 pm
I rarely use the in-build script engine but I have the very same issue when trying to debug. I claimed it to my very old OS and just use Run (with no debug) wehn needed. Probably someone else knows what to install to get the debugger to run. If not contact Sparx' support via mail.

Also look at Arshad's suggestion. The GetElementSet is probably better in your case.

q.
Title: Re: C# addin - listing all objects inside a project
Post by: jk on July 12, 2018, 06:41:11 pm
Ok thanks,

but -sorry- I do not know how to print (in the console) or in a file the respective ElementIDs.

Code: [Select]
var elementCollection as EA.Collection;
elementCollection = Repository.GetElementSet("select t_object.Object_ID from t_object where object_type = 'Port' and (select count(*) from t_connector where t_connector.End_Object_ID = t_object.Object_ID) = 0",2);
// ...here I would like to get the console output/file write...of all respective IDs which are not connected

To the second issue (SScripter.exe error): When I run it in debug mode, I can not copy the whole debug output to clipboard.


 :-[
Title: Re: C# addin - listing all objects inside a project
Post by: qwerty on July 12, 2018, 06:50:07 pm
As the help says: it's a collection. So you need to iterate and use GetAt.

q.