Interactive Selection

Interactive Selection

petrxn
Advocate Advocate
1,890 Views
2 Replies
Message 1 of 3

Interactive Selection

petrxn
Advocate
Advocate

Hello

I am trying to understand how to select element of pick point trought API.

I have found example in API manual, chapter "Interactive selection". Everything seems be clear but finally this example (and also others which I have found on web) doesnot work as I am expecting.

There is example:

Public Sub TestSelection()
    ' Create a new clsSelect object.
    Dim oSelect As New clsSelect

    ' Call the pick method of the clsSelect object and set
    ' the filter to pick any face.
    Dim oFace As Face
    Set oFace = oSelect.Pick(kPartFaceFilter)

    ' Check to make sure an object was selected.
    If Not oFace Is Nothing Then
        ' Display the area of the selected face.
'''' there is cursor and content menu correct 
         MsgBox "Face area: " & oFace.Evaluator.Area & " cm^2"
'''' now is cursor and content menu back as is during selection, why?
    End If
End Sub

' and class code
' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents

' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean

Public Function Pick(filter As SelectionFilterEnum) As Object
    ' Initialize flag.
    bStillSelecting = True

    ' Create an InteractionEvents object.
    Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

    ' Ensure interaction is enabled.
    oInteractEvents.InteractionDisabled = False

    ' Set a reference to the select events.
    Set oSelectEvents = oInteractEvents.SelectEvents

    ' Set the filter using the value passed in.
    oSelectEvents.AddSelectionFilter filter

    ' Start the InteractionEvents object.
    oInteractEvents.Start

    ' Loop until a selection is made.
    Do While bStillSelecting
        ThisApplication.UserInterfaceManager.DoEvents
    Loop

    ' Get the selected item. If more than one thing was selected,
    ' just get the first item and ignore the rest.
    Dim oSelectedEnts As ObjectsEnumerator
    Set oSelectedEnts = oSelectEvents.SelectedEntities
    If oSelectedEnts.Count > 0 Then
        Set Pick = oSelectedEnts.Item(1)
    Else
        Set Pick = Nothing
    End If

    ' Stop the InteractionEvents object.
    ' System.Threading.Thread.Sleep (100)
    oInteractEvents.Stop


    ' Clean up.
    Set oSelectEvents = Nothing
    Set oInteractEvents = Nothing
End Function

Private Sub oInteractEvents_OnTerminate()
    ' Set the flag to indicate we're done.
    bStillSelecting = False
End Sub

Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)

    ' Set the flag to indicate we're done.
    bStillSelecting = False
End Sub

I am able to select face, during selection is cursor shown as arrow with plus symbol, content menu show correctly zoom and pan commands. Unfortunatelly when this selection is done and message box show the value, the cursor and content menu does not return to correct state. Cursor is still with plus and content menu with zoom&pan. I have found that problem is with messagebox, just before messagebox is shown the cursor and content menu return to correct state , but after messagebox is shown and closed, then cursor and content menu is wrong. Why?

Finally I need it for my addin in C#, is there and better way how to select item or input 2d point?

I use Inv 2013.

 

Many thanks for help

Petr

0 Likes
Accepted solutions (1)
1,891 Views
2 Replies
Replies (2)
Message 2 of 3

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi Petr,

 

The simplest solution seems to be adding 

  ThisApplication.CommandManager.StopActiveCommand

after

  oInteractEvents.Stop

 

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 3

petrxn
Advocate
Advocate

Thank you,

I have found this solution too, but it looks little strange for me. 

Anyway it works correctly now.

 

Cheers,

0 Likes