-1

I have own profile in EA and i can give a own note element with a specific tag value. My problem is, that i want select some note in project and change tag value through add-in. How can i get current selected element ?

enter image description here

CathalMF
  • 9,705
  • 6
  • 70
  • 106
Pepo
  • 3
  • 2

3 Answers3

2

RTM: Respository.GetTreeSelectedObject

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/15647274) – Psi Mar 26 '17 at 16:12
  • It doesnt give me element but object only. I need element, because i need change tag value. – Pepo Mar 26 '17 at 17:57
  • Well, the object IS the element. The tags are in the Element.TaggedValues collection. – qwerty_so Mar 26 '17 at 18:47
  • @Psi Well, actually it DOES give an answer. The question is either too basic of not elaborated well. Let's see, – qwerty_so Mar 26 '17 at 18:48
  • 1
    Respository.GetTreeSelectedObject will give you the item selected in the project Browser – Mart10 Mar 27 '17 at 13:30
  • @MartinGrégoire Depends on how you interpret the OP's question "get current selected element" – qwerty_so Mar 27 '17 at 13:40
  • @ThomasKilian In this case he's looking for a note, which you will never get in the Project Browser – Mart10 Mar 27 '17 at 13:42
  • @ThomasKilian but it gives me this `Unable to cast COM object of type 'System.__ComObject' to interface type 'EA.Element'. This operation failed because the QueryInterface call on the COM component for the interface ` – Pepo Mar 27 '17 at 13:51
  • @MartinGrégoire that is what i need :) – Pepo Mar 27 '17 at 13:52
  • 1
    @pepo, see my replies with Thomas. He gave you the code for an element selected in the project browser, which in this case, on the screenshot, what is selected is a diagram. When trying to assign an EA.Element to an object which is actually a Diagram, it will give you this error – Mart10 Mar 27 '17 at 14:08
2

You can use

Repository.GetContextObject()

to get the currently selected Object.
To get the type of the object, use Repository.GetContextItemType()

you can then assign an EA.Element type to the object returned by Repository.GetContextObject()

 private void getSelectedElement(EA.Repository Rep)
            {
                EA.Element ele;
                switch(Rep.GetContextItemType())
                {
                    case EA.ObjectType.otElement:
                        {
                            ele = Rep.GetContextObject();
                            //Operations on the selected element
                            break;
                        }
                } 
            }

If you want to know all the possible types, see the documentation (This is for EA 13)

Mart10
  • 758
  • 3
  • 14
-1

I use this function (VBScript). It combines answers from Mart10 and qwerty_so:

function getSelectedElement() ' as EA.Element
    
    dim sel
    
    set sel = Repository.GetContextObject
    if sel is nothing then sel = Repository.GetTreeSelectedObject()
    
    if sel.ObjectType <> otElement then set sel = nothing
    
    set getSelectedElement= sel
end function

Primarily it looks for the active Diagram's selection and secondarily in the Project Browser, finally filters for EA.Element-s .

NOTE: The purpose of method GetContextItemType() is not obvious to me, as each Object knows it's type by property ObjectType.

Sam Ginrich
  • 661
  • 6
  • 7