Book a Demo

Author Topic: object type of root node  (Read 4572 times)

schnix

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
object type of root node
« on: August 11, 2008, 09:03:47 pm »
hi

i'm working on an add-in where i need access to marked elements in the project browser. i'm using the Repository.GetContextItem(out item) method which returns the object type and a pointer to the marked element.

my problem now is, that the method returns "otNone" when i try to access a root node. so i cant cast into any EA object which means i cant use it.

what do i miss?

schnix

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: object type of root node
« Reply #1 on: August 12, 2008, 12:03:26 am »
Can you cast to Element or Package? [Regardless of the otNone return.]

If so, you should be able to grab the ElementGUID or PackageGUID (they should be the same for a root node, if both exist) and then retrieve the appropriate object from the Repository.

Not perfect perhaps, but if it works it could get you out of this bind.

David
No, you can't have it!

schnix

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: object type of root node
« Reply #2 on: August 12, 2008, 12:30:18 am »
no i cant cast to element or package

the error message isnt the standard cast error like
"unable to cast COM object of type ..."
which occures i.e. when trying to cast an element into a package

instead it says
"object reference not set to an instance of an object"
and i have no idea what exactly that means

sorry i didnt mentioned this in my first post, i just realized it  

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: object type of root node
« Reply #3 on: August 12, 2008, 02:50:02 am »
That sounds like you are not getting anything back from your earlier call - likely the call to GetContextItem. Many of the API methods return null (or nothing as the case might be) when they fail to obtain a reference.

I suspect without proof that attempts to obtain the 'type' of a null reference might silently fail with an otNone value.

If the above are true then you'd get the results you describe.

You describe this as happening when you access "a root node" in the Browser. Do you mean the top (default root) node, or have you confirmed whether this happens if the Browser has an additional (user added) root node selected?

Perhaps there is some way to eliminate other possibilities, or to otherwise test for a root node being selected. [I'm not sure though.] Even so, you'd have to figure out which root was selected if this happens with all project roots.

David
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: object type of root node
« Reply #4 on: August 12, 2008, 02:54:21 am »
Can you use one or more of the GetTreeSelected... methods instead?
No, you can't have it!

schnix

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: object type of root node
« Reply #5 on: August 12, 2008, 05:11:50 pm »
you suspected right, GetContextItem returned null (should have come to my mind, too :-[ ...). also the GetTreeSelectedItem method worked.
thanks for your help

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: object type of root node
« Reply #6 on: August 12, 2008, 10:37:31 pm »
I should have thought of that the first time. Sorry about the delay.

The main thing is that you're moving forwards again...
No, you can't have it!