/// <summary> /// Get element from Context element. Possible inputs are: Attribute, Operation, Element, Package /// </summary> /// <param name="rep"></param> /// <returns></returns> public static EA.Element GetElementFromContextObject(EA.Repository rep) { EA.Element el = null; EA.ObjectType objectType = rep.GetContextItemType(); switch (objectType) { case ObjectType.otAttribute: var a = (EA.Attribute)rep.GetContextObject(); el = rep.GetElementByID(a.ParentID); break; case ObjectType.otMethod: var m = (Method)rep.GetContextObject(); el = rep.GetElementByID(m.ParentID); break; case ObjectType.otElement: el = (EA.Element)rep.GetContextObject(); break; case ObjectType.otPackage: EA.Package pkg = rep.GetContextObject(); el = rep.GetElementByGuid(pkg.PackageGUID); break; case ObjectType.otNone: EA.Diagram dia = rep.GetCurrentDiagram(); if (dia?.SelectedObjects.Count == 1) { var objSelected = (EA.DiagramObject)dia.SelectedObjects.GetAt(0); el = rep.GetElementByID(objSelected.ElementID); } break; default: MessageBox.Show(@"No Element, Attribute, Operation, Package selected"); break; } return el; }