Book a Demo

Author Topic: Select EA Model Element  (Read 8829 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Select EA Model Element
« on: December 09, 2013, 07:14:30 pm »
Hello!
Is there an API way to access  several types of model elements which the user selected from model browser?

-The user selected some model elements and I want to access all elements which on scope.

Thanks in advance!

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Select EA Model Element
« Reply #1 on: December 09, 2013, 07:31:12 pm »
You have two options:
1) You want to have the selected elements in the Project Browser: use Repository.getTreeSelectedElements() method.
2) You want to have the selected elements in a diagram: use Diagram.SelectedObjects property.

Additional information can be found in EA help.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Select EA Model Element
« Reply #2 on: December 09, 2013, 07:57:24 pm »
Thank you for quick reply!
Any idea why this collection is empty despite selection of elements in model browser?  :(

Code: [Select]
EA.Collection listSelectedElements=Repository.GetTreeSelectedElements();
                  if(listSelectedElements.Count > 0)
                  for(short i=0;i<listSelectedElements.Count;i++)
                  {
                        MessageBox.Show(listSelectedElements.GetAt(i).GetType().ToString());
                  }//for

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Select EA Model Element
« Reply #3 on: December 09, 2013, 08:02:09 pm »
Might be a bug.

I always use Repository.GetContextObject() because that will return the selected element regardless of selection in project browser or diagram.
But that doesn't work for multiple selection.

Geert

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Select EA Model Element
« Reply #4 on: December 09, 2013, 08:11:56 pm »
What should I do in order to get selected elements???
Well, I want to try some SQL query statement.
Is there a property of EA.Element which indicates if it is currently selected?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Select EA Model Element
« Reply #5 on: December 09, 2013, 11:36:13 pm »
Quote
What should I do in order to get selected elements???
Well, I want to try some SQL query statement.
Is there a property of EA.Element which indicates if it is currently selected?
If you really think that then you haven't quite understood the concept of the client-server architecture of EA (or any client-server architecture for that matter).
Not even EA stores the "currently selected in the client" values in the database.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Select EA Model Element
« Reply #6 on: December 10, 2013, 01:15:38 am »
Repos.GetTreeSelectedElements gives you the elements currently selected in the project browser. Diagram.SelectedObjects the elements selected in a diagram. That's what you can have.

q.

P.S. I found that in my mail:
Quote
              if (activeRepository.EARepository.GetTreeSelectedElements().Count > 1)  //Only use if multiple selected... (Seems to be a bug in 858 if only one selected)
Though it's some time ago (build 858) it might be buggy still.
« Last Edit: December 10, 2013, 01:18:40 am by qwerty »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Select EA Model Element
« Reply #7 on: December 10, 2013, 09:33:52 am »
What type of items are you selecting in the Project Browser?  GetTreeSelectedElements() will only return selected EA.Element types such as Class, Interface, UseCase, etc.  It will not return Packages, Diagrams, Attributes or Operations.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Select EA Model Element
« Reply #8 on: December 19, 2013, 10:05:13 pm »
Hello!
I wrote an add-in which can be invoked when a diagram is opened by the user.
Is there a way it will be possible just to select the diagram instead of open it?

Selecting a package is possible like this:
Code: [Select]
Repository.GetTreeSelectedPackage();
But a diagram has to be opened:  :-[
Repository.GetCurrentDiagram();

Thanks in advance!