Author Topic: Selected elements in diagram  (Read 4669 times)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Selected elements in diagram
« on: May 10, 2012, 10:38:33 pm »
When you right click any element or connector in a diagram then EA offers the addin-menu in the context. I faintly remember a method to retrieve the selected element(s) in a diagram. But I can't find it now. How can I find out which element(s)/connector is/are selected in the diagram from an add-in?

q.

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Selected elements in diagram
« Reply #1 on: May 10, 2012, 11:16:43 pm »
The Diagram class contains a read only collection property SelectedObjects, I guess that's what you're looking for (see http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/diagram2.html).

HTH
Günther

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Selected elements in diagram
« Reply #2 on: May 10, 2012, 11:44:59 pm »
Doh! I like EA. GetTreeSelectedObject is in Repository. Of course this one is in Diagram. I was looking for GetDiagramSelectedObject or the like...

Thanks!

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Selected elements in diagram
« Reply #3 on: May 11, 2012, 12:38:12 am »
Interestingly there is also a property SelectedConnector (which I did not expect...). The documentation tells this is r/w. For curiosity sake I tried setting this to zero (thus deselecting the connector). Well, that did not work. I guess this is an error in the documentation and it's meant to be r/o -> Roy?

q.
« Last Edit: May 11, 2012, 12:38:33 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Selected elements in diagram
« Reply #4 on: May 11, 2012, 03:38:58 pm »
I always use getContextItem:
Here's the code I use for getting and setting the selected element from 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;
        }

        
      }
          set
          {
                if (value is Package)
                {
                      this.wrappedModel.ShowInProjectView(((Package)value).wrappedPackage);
                }
                else if (value is ElementWrapper)
                {
                      this.wrappedModel.ShowInProjectView(((ElementWrapper)value).wrappedElement);
                }
              else if (value is Operation)
              {
                  this.wrappedModel.ShowInProjectView(((Operation)value).wrappedOperation);
              }
              else if (value is Attribute)
              {
                  this.wrappedModel.ShowInProjectView(((Attribute)value).wrappedAttribute);
              }
              else if (value is Parameter)
              {
                    Operation operation = (Operation)((Parameter)value).operation;
                    this.wrappedModel.ShowInProjectView(operation.wrappedOperation);
              }
          }
    }

But that only returns one object, not a collection.

Geert
« Last Edit: May 11, 2012, 03:40:11 pm by Geert.Bellekens »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Selected elements in diagram
« Reply #5 on: May 11, 2012, 07:22:14 pm »
Truly Konzistend. Multiple elements selected are not in a "real" context. Neither in a diagram nor in the browser.

However, thanks for the note :-) Might be useful, though.

q.