Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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
-
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
-
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,
-
Yes you can get the connectors information of an element in the Connector collection of element class.
foreach(EA.Connector con in theElement.Connectors)
{
//your code
}
-
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.
-
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.
-
Yes. You can create a single query to return that. I'll have a look into that after lunch. (No promises, though)
q.
-
Oh thanks.
That would be nice! :) :)
I tried it, but it isnt working.
BR
-
Here it is:
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.
-
Thank you, I will try it! :)
-
I do not understand what the System Output is printing.
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!
-
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.
-
Hello,
now I added your example query into the function of the Script "RecursiveModel Dump Example" for testing:
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!
-
The entire piece of code wont work together in the way youve used .
- In your query you are getting entire columns from t_object. Get Object_ID alone
- Repository.SQLQuery - Will return Object ID's in the XML format. You need to get that list and iterate it
- Repository.GetElementByID - You can pass only one object ID in this call at a time .
- You should use Repository.GetElementSet to get the details from a list of objectID's
To Use ElementSet
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
-
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.
-
Ok thanks,
but -sorry- I do not know how to print (in the console) or in a file the respective ElementIDs.
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.
:-[
-
As the help says: it's a collection. So you need to iterate and use GetAt.
q.