Book a Demo

Author Topic: eliminating orphaned elements (c#)  (Read 5911 times)

db

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
eliminating orphaned elements (c#)
« on: March 18, 2010, 12:18:39 am »
Hi, I'm trying to retrieve the elements from the Project Browser in my c# application. At the moment I am retrieving all the elements from the Project Browser + some duplicates that don't appear in EA. However these elements appear in EA if i run a search with the "Find Orphans" preset.
Is there any way to tell if an element passed to my application is an orphan? (how do these orphans appear and is there any way to delete them? All i could find in the EA documentation about orphans is the Find Orphans search paragraph)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #1 on: March 18, 2010, 06:57:07 am »
"Orphans" are elements that are represented in NO diagrams.

Therefore their Element.Diagrams collection should be empty.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #2 on: March 18, 2010, 08:30:11 am »
Actually, Element.Diagrams is the list of diagrams owned by the element.  Not the list of diagrams it appears on.

Currently a sql query would be the only way to check for an element being orphaned (that I can think of) but an Element.Usage collection is one of a big list of additions to the automation interface that I plan to push for when I get the time to do it.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #3 on: March 18, 2010, 09:07:40 am »
Another alternative might be to use GetElementsByQuery() on the Repository object to return a collection of all orphans in the current model and then see if your element is in this collection.

E.g.
Set Orphans = Repository.GetElementsByQuery("Find Orphans", "")

This could be quite slow though.  Would be far more efficient to just use a sql query as Simon suggested.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #4 on: March 18, 2010, 09:32:01 am »
Quote
how do these orphans appear and is there any way to delete them?
As Paolo mentioned, an orphan is an element that doesn't appear in any diagram. This is perfectly valid. In fact it's perfectly valid to have a model without any diagrams at all in which case all elements will be orphans. So by all means delete them if they need deleting, but not just because they're orphans.
The Sparx Team
[email protected]

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #5 on: March 18, 2010, 10:16:46 am »
Quote
Actually, Element.Diagrams is the list of diagrams owned by the element.  Not the list of diagrams it appears on.
[size=18]...[/size].
And so it is!

That will teach me to try to answer questions at 3:57am in the morning!

Just because I can't sleep, it doesn't mean my brain is awake!

Apologies...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

db

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: eliminating orphaned elements (c#)
« Reply #6 on: March 19, 2010, 04:03:32 am »
Hi guys, thanks for the answers. It seems I was on the wrong track. The orphaned elements were created because I deleted a diagram from EA (i deleted the diagram because i thought that i was having duplicate elements because of it). Anyway the diagram is back in the .eap file, orphan elements are no longer in the "Orphaned elements" search but the duplicate elements are still there. Here's a picture that shows the ProjectBrowser:http://i.imgur.com/PzjuV.png
For this project i get in my application the followin tree:
...
-Software_Modules
  -P1
  -P2
  -P3
  ...
  -mname
    -P1
    -P2
    -P3
    ....
So ,in my application, the elements P1, P2, P3 appear twice with different parents (Software_Modules and mname) altough they appear only once in the project browser. I have compared: isLeaf, isActive, PackageID, ParendID, Persistence and all the Properties and CustomProperties of these elements and they are the same so i have no way to differentiate between them.
My 2 questions are:
1. is there any way that these elements are somehow hidden in the project browser and the results that i get are correct or is my code broken :)
2. if my code is correct what should i check in order to differentiate between the duplicate elements.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: eliminating orphaned elements (c#)
« Reply #7 on: March 22, 2010, 08:26:57 pm »
Their ElementID, GUID, or their ParentID/PackageID

Geert