Author Topic: How to determine the selected package  (Read 3553 times)

Hrungdak

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
How to determine the selected package
« 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


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to determine the selected package
« Reply #1 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
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

Hrungdak

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to determine the selected package
« Reply #2 on: August 10, 2016, 06:50:33 pm »
Hello Geert,

thanks a lot, exactly what i needed.

Greetings
Alex