A customer from Munich approached us with the following interesting questions:
- In the samples (eg. Object Highlighting) they use AdView.DocumentHandler.ObjectNodes, but this does not work (IE gives an undefined error - sample doesn't work). It's a bit strange, since the samples try to use it, but it isn't even stated in the API documentation.
Anil Narra, one of our developers, replied: "First off, our object APIs went through two distinct iterations. The original object API was 2D only so we wrote a new unified object API which works the same for both 2D and 3D. Both the IAdViewerEvents::OnSelectObject event and IAdECompositeViewer::ObjectsSelected property are of the former group and while not deprecated for 2D, have never really worked for 3D so you shouldn’t be using them (it doesn’t surprise me that ObjectsSelected blows up for 3D sections).
That said, we have attempted to come up with a unified object API which operates the same for both 2D and 3D. Here is the gist of what you need to do:
1. Trap for the newer OnSelectObjectEx event but don’t handle it so that the default event handling will still occur. Unfortunately the new selection set isn’t created until such time as the default handler does its thing so you can’t look at the selection set inside your event handler. So instead, set a global boolean called “OnSelectObjectExCalled” to true (the purpose of this will become clear in a minute).
2. Right after the selection set changes, there will be a repaint (to highlight the new selections) so trap out the ensuing OnBeginDraw event (or OnEndDraw if you rather) and see if OnSelectObjectExCalled is true. If so, the selection set is now valid and you can fetch it via the IAdContent::Objects(ObjectType::Selected) property (be sure and set the OnSelectObjectExCalled member back to false). It would have been nice had we created a post “OnSelectObjectHappened” type event in which the new selection set would already exist but we didn’t so you’ll have to resort to this repaint trapping scheme instead.
3. The IAdContent::Objects(ObjectType::Selected) property returns an IAdCollection of IAdObject’s. These are the object’s themselves so you don’t need to use the IAdContent2::Object property (returns the IAdObject for an object with the given id). For each item in the collection, you can invoke its “Properties” property to get an IAdCollection of all the IAdProperty items possessed by the object.
Ps: You can also control the selection set programmatically. First call IAdContent::CreateUserCollection to return an empty IAdUserCollection. You can then add to it the IAdObject interfaces of those objects you want selected. Once complete, you can “set” the IAdContent::Objects(ObjectType::Selected) property to your collection to effect the desired selection."
Thank you, Anil.