I'm new to ADR API and trying to get access to a selected object in a3D view. The story so far following the documentation, sample code and browsing the web...
1. I have trapped the OnSelectObjectEx event
2. I've got to MyObjects = ObjectContent.Objects(1) which I believe returns the selected object(s) into MyObjects
The problem is that 0 objects are returned, even though clearly an object has been selected since the event is fired. If I use
MyObjects = ObjectContent.Objects(0) then I get all objects in the view, so I think I'm on the right path.
What am I doing wrong? BTW, I'm using VB.Net.
Thanks in advance...
Thank you for reporting this issue.
Could you please explain how did you get an object being selected in your code?
Hi Herbert,
I'm not selecting the object in code...I'm selectling an object in the ADR control, which by default opens the Object Properties palette, and the Model palette.
What I want to do is to use the OnSelectObjectEx event to gain access to the properties of the selected object, however, using the sample code...
PrivateSub dwfSmall_OnSelectObjectEx(ByVal sender AsObject, ByVal e As AxExpressViewerDll.IAdViewerEvents_OnSelectObjectExEvent) Handles dwfSmall.OnSelectObjectEx
Dim CompositeViewer As IAdECompositeViewer
Dim Section As IAdSection
Dim MyObjects As AdCommon.IAdCollection
Dim MyObjectProperties As AdCommon.IAdCollection
Dim MyObjectsNamedCollection As AdCommon.IAdUserCollection
Dim ObjectContent As IAdContent
Dim MyObject As IAdObject
Dim MyObjectProperty As IAdProperty
Dim ObjectName AsString
Dim Idx AsInteger
Idx = 1
CompositeViewer = dwfSmall.ECompositeViewer
Section = CompositeViewer.Section
ObjectContent = Section.Content
'Create a user collection of selected objects
MyObjectsNamedCollection = ObjectContent.CreateUserCollection
'Get all the objects in the current section
MyObjects = ObjectContent.Objects(1) '1 is to return selected
ForEach MyObject In MyObjects
MyObjectProperties = MyObject.Properties
ForEach MyObjectProperty In MyObjectProperties
If MyObjectProperty.Name = "Name"And MyObjectProperty.Value = "KITCHEN"Then
ObjectName = MyObjectProperty.Name + " " + Str(Idx)
Idx = Idx + 1
MyObjectsNamedCollection.AddNamedItem(MyObject, ObjectName)
'Add the named object to a selection set
EndIf
Next
Next
EndSub
... I get 0 objects returned. If I use "MyObjects = ObjectContent.Objects(0)" I then get all objects in the model and can iterate thru them but this is inefficient - I should be able to get access to the selected oblect??
Not sure what I'm doing wrong.
Thanks
Thank you for your feedback.
I can get selected objects with your code above.
In your code, you're looking for objects which property "Name" is "KITCHEN", from all selected objects.
Please remove the condition:
If MyObjectProperty.Name = "Name" And MyObjectProperty.Value = "KITCHEN" Then
And try it again.
Good luck! 🙂
Thanks Herbert...
I'm not sure we're communicating. The code line "MyObjects = ObjectContent.Objects(1)" gives MyObjects.Count=0, therefore does not get into the For Each loop.
If the OnSelectObjectEx event is fired and trapped, why is MyObjects.Count=0? If I use the code "MyObjects = ObjectContent.Objects(0)" then MyObjects.Count=89 (the total number of objects)!
Thanks again
Phil
Thank you for your feedback.
How did you make OnSelectObjectEx event fired? If there are some objects being selected, ObjectContent.Objects(1) should return them.
Thanks Herbert,
Yes, I'm selecting a single object in the ADR control which fires the OnSelectObjectEx event. THe problem is that ObjectContent.Objects(1) retuns a count of 0.
Any ideas?
Regards
Phil
Thank you for your feedback.
I can get selected objects with your code. Could you please attach a sample application for us to reproduce this issue?
Thanks Herbert,
App attached. There's not much to it...just a model loaded from URL into the control and the event handler. Also, I'm using VS 2008 on Win 7 x64 compiled to x86.
Regards
Phil
It does not work on my machine.
Hi,
Apologies for not getting back earlier - have had to work on other projects. Can we please resume this issue? From the code shown previously I should be able to access the properties of a single selected object, the line of code in particular is "
MyObjects = ObjectContent.Objects(1)" however this returns 0 objects.
There is no preceding code, simply embedding a DWF model in a Windows form, running the application and selecting an object.
Thanks for your assistance in resolving this.
Thank you for your feedback.
The object will be marked as "selected" only AFTER the OnSelectObjectEx event. So it too early to get selected objects in OnSelectObjectEx handler.