Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hrungdak on August 10, 2016, 05:08:48 pm
-
Hi all
I am writing an Add-Id. The user selects a package, right-clicks on it and calls the menu that i provide through my Add-in.
In my code i have to use this package and work with it. How can i find out which package the user has right-clicked on?
Greetings
Alex
-
Hi Alex,
You can use Repository.GetContextItem()
I'm using this code in my Model wrapper class (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/Model.cs)
/// the Element currently selected in EA
public UML.Classes.Kernel.Element selectedElement {
get {
Object selectedItem;
try
{
this.wrappedModel.GetContextItem(out selectedItem);
return this.factory.createElement(selectedItem);
}
catch (COMException)
{
//something went wrong
return null;
}
}
The factory figures out what object is selected and returns the appropriate wrapper.
Geert
-
Hello Geert,
thanks a lot, exactly what i needed.
Greetings
Alex