Author Topic: C# addin - listing all objects inside a project  (Read 3396 times)

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
C# addin - listing all objects inside a project
« 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


Dahsra

  • EA User
  • **
  • Posts: 225
  • Karma: +17/-1
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #1 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

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #2 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,



Dahsra

  • EA User
  • **
  • Posts: 225
  • Karma: +17/-1
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #3 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
}

qwerty

  • EA Guru
  • *****
  • Posts: 12329
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #4 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.

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #5 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.

qwerty

  • EA Guru
  • *****
  • Posts: 12329
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #6 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.

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #7 on: July 11, 2018, 08:42:51 pm »
Oh thanks.

That would be nice!  :)  :)


I tried it, but it isnt working.



BR
« Last Edit: July 11, 2018, 08:55:39 pm by jk »

qwerty

  • EA Guru
  • *****
  • Posts: 12329
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #8 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.

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #9 on: July 11, 2018, 10:05:15 pm »
Thank you, I will try it!  :)

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #10 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!

qwerty

  • EA Guru
  • *****
  • Posts: 12329
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #11 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.

jk

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #12 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!

Dahsra

  • EA User
  • **
  • Posts: 225
  • Karma: +17/-1
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #13 on: July 12, 2018, 04:49:38 pm »
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
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

HTH
Arshad
« Last Edit: July 12, 2018, 05:06:51 pm by Arshad »

qwerty

  • EA Guru
  • *****
  • Posts: 12329
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: C# addin - listing all objects inside a project
« Reply #14 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.