Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: jörg on December 17, 2020, 03:54:55 am
-
Hi Specialists!
In my addin I'm facing a behaviour which I can't explain.
I'm iterating the DiagramObjects of a diagram and then for each DiagramObject I try to retrieve the related Element from the repository using the GetElementByID(ElementID)-Function of the Repository class to get further information about the element. The diagram is of course in the same repository.
This works very well for many diagrams but in one diagram the GetElementByID-Function throws an exception saying that it could not find the element ("Can't find matching ID"). The ObjectType is - of course - otDiagramObject and the GetType-Function of the DiagramObject class tells me it is a System_ComObject. The user (I don't have access to the EA project myself) searched the diagram and it's Elements and could not find any COM object. Re-saving the diagram (after a slight change) did not change anything. When he exports the package and imports it into a new project, the error is gone.
So I have the following questions (and hope for answers 8)):
1. Can anyone explain this behaviour?
2. How can I find out which element is causing the error?
3. Why is the error persistant over re-saving but disappears after exporting and re-importing into another project?
Question 2 is the most important one which I need an answer for. The others are for my curiosity
Thanks in advance,
Jörg
-
Hi Jörg,
You probably have a integrity issue here.
When you delete an element, EA will clean up it's dependencies such as connectors to/from this element, diagramObjects referencing this element etc..
Now suppose EA crashes before it was able to clean up all dependencies. You could end up with a diagramObject that points to an element that doesn't exist anymore.
Most of these issues will be fixed running the project integrity check.
XMI import export does it's own "integrity" check and won't create diagramObjects for non existing elements.
Geert
-
I think Geert has hit the nail on the head as I've had similar behaviour fixed by running the integrity checker.
Configure Tab>Integrity>Project Integrity
You can run the report before fixing
Needless to say back up first before attempting to fix just incase something nasty happens.
Merry Christmas
-
Thanks for the answers, this was my guess, too.
In my special case I want to detect changes in a diagram or the elements it contains. For this purpose I iterate over the elements creating a hash value for comparision. So I decided to just ignore the missing element. I an element was removed from the diagram I see this in the diagrams "modified" date.
-
A deleted elements seems an important enough change not be ignored.
Also I wouldn't necesarrily count on the diagrams modified date. There can be lots of reasons the modified date wasn't updated, but it was still changed.
Geert