Design Review
Welcome to Autodesk’s Design Review Forums. Share your knowledge, ask questions, and explore popular Design Review topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Not able to return the selected object

11 REPLIES 11
Reply
Message 1 of 12
phillip.mcneill
554 Views, 11 Replies

Not able to return the selected object

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...

11 REPLIES 11
Message 2 of 12

Thank you for reporting this issue.

 

Could you please explain how did you get an object being selected in your code?



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 3 of 12

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

Message 4 of 12

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! 🙂

 



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 5 of 12

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

Message 6 of 12

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.



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 7 of 12

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

Message 8 of 12

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?



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 9 of 12

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

Message 10 of 12

It does not work on my machine.



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 11 of 12

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.

Message 12 of 12

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.



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report