Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hrungdak on August 10, 2016, 05:08:48 pm

Title: How to determine the selected package
Post 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

Title: Re: How to determine the selected package
Post by: Geert Bellekens on August 10, 2016, 05:14:25 pm
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)
Code: [Select]
/// 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
Title: Re: How to determine the selected package
Post by: Hrungdak on August 10, 2016, 06:50:33 pm
Hello Geert,

thanks a lot, exactly what i needed.

Greetings
Alex