'Enterprise architect : C# add-in current selected item tagged value
Solution 1:[1]
You can use
Repository.GetContextObject()
to get the currently selected Object.
To get the type of the object, use Repository.GetContextItemType()
you can then assign an EA.Element type to the object returned by Repository.GetContextObject()
private void getSelectedElement(EA.Repository Rep)
{
EA.Element ele;
switch(Rep.GetContextItemType())
{
case EA.ObjectType.otElement:
{
ele = Rep.GetContextObject();
//Operations on the selected element
break;
}
}
}
If you want to know all the possible types, see the documentation (This is for EA 13)
Solution 2:[2]
RTM: Respository.GetTreeSelectedObject
Solution 3:[3]
I use this function (VBScript). It combines answers from Mart10 and qwerty_so:
function getSelectedElement() ' as EA.Element
dim sel
set sel = Repository.GetContextObject
if sel is nothing then sel = Repository.GetTreeSelectedObject()
if sel.ObjectType <> otElement then set sel = nothing
set getSelectedElement= sel
end function
Primarily it looks for the active Diagram's selection and secondarily in the Project Browser, finally filters for EA.Element-s .
NOTE: The purpose of method GetContextItemType() is not obvious to me, as each Object knows it's type by property ObjectType.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mart10 |
| Solution 2 | Funk Forty Niner |
| Solution 3 |

