EA.Element myElement = Repository.GetElementByID(1234); if(myElement != null) { //do something with the element }
EA.Element myElement = currentDiagram.GetDiagramObjectByID(5678).Element; if(myElement != null) { //do something with the element }This code gets the current diagram and retrieves a diagram object with ID 5678, which is linked to an element in the model. Then, it accesses the element through the `Element` property of the diagram object and assigns it to the variable `myElement`. Again, it checks if the element exists before performing any operations. The `GetElementByID` method is part of the `EA.Repository` interface that is provided by the Enterprise Architect automation API. This API is packaged in the `Interop.EA.dll` assembly, which can be found in the installation directory of Enterprise Architect.