vb.net simple selection not working

vb.net simple selection not working

matt_jlt
Collaborator Collaborator
3,480 Views
8 Replies
Message 1 of 9

vb.net simple selection not working

matt_jlt
Collaborator
Collaborator

Basically i have some code that gets the parts list on a drawing sheet and if there is more than one allows you to manually select which to use.

It is a sub that calls up a selection class and defines the filter to be used. My problem is that once the selection event for multiple partlsists has been initialised i cannot select the parts lists. I'm not sure if it's the selection filter or the still selecting do events loop.

 

I have tried using the other doevents methods but it doesn't seem to work.


The code is below, If anyone could help it would be much appreciated. I have have left this problem unsolved for a long time and am finally getting to finish my addins.

Private Sub Total_Mass
' Define variables
Dim oDoc As Inventor.DrawingDocument
Dim oSheet As Inventor.Sheet
Dim oPListColl As Inventor.PartsLists
Dim oPList As Inventor.PartsList
Dim oPListCount As Integer

' Set references to variables
oDoc = ThisApplication.ActiveDocument
oSheet = oDoc.ActiveSheet
oPListColl = oDoc.ActiveSheet.PartsLists

' Reset Values
oPListCount = 0
oPList = Nothing

Select Case oPListColl.Count
Case 0
MsgBox("There are no parts lists on the active sheet", MsgBoxStyle.Exclamation)
Me.Close
Case 1
oPList = oDoc.ActiveSheet.PartsLists.Item(1)
GoTo PListSelected
Case Is > 1
GoTo MSelectPList
End Select


MSelectPList: ' Manual Parts List Selection Process

' Declare a variable and create a new instance of the select class.
Dim oSelect As New clsSelect

' Call the Pick method of clsSelect object and set filter to pick any parts list.
oPList = oSelect.Pick(SelectionFilterEnum.kDrawingPartsList Filter) ' **************** Not Sure if the filter is not working properly
MsgBox("Parts List Title = " & oPList.Title, MsgBoxStyle.Information)
End Sub


Public Class clsSelect
' Declare the event objects
Private WithEvents oInteraction As Inventor.InteractionEvents
Private WithEvents oSelect As Inventor.SelectEvents

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

Public Function Pick(ByVal filter As Inventor.SelectionFilterEnum) As Object ' dont know if filter definition is correct
' Initialize flag.
bStillSelecting = True

' Create an InteractionEvents object.
oInteraction = ThisApplication.CommandManager.CreateInteractionEvents

' Define that we want select events rather than mouse events.
oInteraction.SelectionActive = True

' Set a reference to the select events.
oSelect = oInteraction.SelectEvents

' Set the filter using the value passed in.
oSelect.AddSelectionFilter(filter)

' The InteractionEvents object.
oInteraction.Start()

' Loop until a selection is made.
Do While bStillSelecting ' *********************************** It gets stuck in this loop
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 Inventor.ObjectsEnumerator
oSelectedEnts = oSelect.SelectedEntities
If oSelectedEnts.Count > 0 Then
Pick = oSelectedEnts.Item(1)
Else
Pick = Nothing
End If

' Stop the InteractionEvents object.
oInteraction.Stop()

' Clean up.
oSelect = Nothing
oInteraction = Nothing
End Function


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


Private Sub oSelect_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, _
ByVal SelectionDevice As Inventor.SelectionDeviceEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View)
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
End Class

0 Likes
Accepted solutions (1)
3,481 Views
8 Replies
Replies (8)
Message 2 of 9

sanjay.ramaswamy
Alumni
Alumni

Do you have any other dialog or a form up at the time? If so, try without the dialog. Also, if you are on Inventor 2011, try the new CommandManager.Pick method - that will significantly simplify your code.

 

0 Likes
Message 3 of 9

matt_jlt
Collaborator
Collaborator

Hi Sanjay, i can't go to 2011 yet as my office has not migrated. There are no other forms or dialogs open. I have a simpler example if the one i used is too complex. It's basically just the selection class straight from the inventor programming help menu and I just can't get it to work, I am using vb.net & Inventor 2010.

Thanks, Matt.

 

    Public Sub Detail_Item()


        ' Declare a variable and create a new instance of the select class.
        Dim oSelect As New clsSelect
        ' Call the Pick method of the clsSelect object and set the filter to pick any face.
        Dim oView As DrawingView
        oView = oSelect.Pick(SelectionFilterEnum.kDrawingViewFilter)
        ' Check to make sure a face was selected.
        If Not oView Is Nothing Then
            MsgBox("View Selected", MsgBoxStyle.Information)
        End If
        Exit Sub

 

Public Class clsSelect
    ' 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(ByVal filter As SelectionFilterEnum) As Object
        ' Initialize flag.
        bStillSelecting = True

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

        ' Ensure interaction is enabled.
        oInteractEvents.InteractionDisabled = False

        ' Set a reference to the select events.
        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() ' Can't Get Past This Loop!!!!!!!!!!!!!
        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
        oSelectedEnts = oSelectEvents.SelectedEntities
        If oSelectedEnts.Count > 0 Then
            Pick = oSelectedEnts.Item(1)
        Else
            Pick = Nothing
        End If

        ' Stop the InteractionEvents object.
        oInteractEvents.Stop()

        ' Clean up.
        oSelectEvents = Nothing
        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 Inventor.View)
        ' Set the flag to indicate we're done.
        bStillSelecting = False
    End Sub
End Class

0 Likes
Message 4 of 9

Anonymous
Not applicable

I would imagin this line is showing up as a error in VB.Net?

ThisApplication.UserInterfaceManager.DoEvents()

 

You need to use the Inventor.Application instead of ThisApplication. 

 

Also for DoEvents if it isn't in a form, I think you need to use something like this

System.Windows.Forms.Application.DoEvents()

 

But even with that I remember fussing with the selection routine for a while and never getting it to work right in .Net. 

0 Likes
Message 5 of 9

matt_jlt
Collaborator
Collaborator

Thanks Kent but I have already tried your suggestions and I forgot to include the imports and declarations for the "ThisApplication" to work, I have searched google and the forums, is there no way around this problem?  This is driving me nuts.

 

Regards, Matt.

0 Likes
Message 6 of 9

matt_jlt
Collaborator
Collaborator

If no one can work out what's wrong, could someone please post a working example of simple selection in vb.net for me? I'm completely stuck and almost all of my addins require a selection process.

 

Thanks, Matt.

0 Likes
Message 7 of 9

matt_jlt
Collaborator
Collaborator

Hi guys, I'm still stuck on this same problem? Someone out there has to have a solution for this (other than upgrading to inventor 2011)? Please help.

0 Likes
Message 8 of 9

Anonymous
Not applicable
Accepted solution

Hello,

 

You can try this. It will work, but needs some fine tuning.

 

Wim

 

Public Class clsSelect
    ' Declare the event objects
    Private WithEvents oInteraction As InteractionEvents
    Private WithEvents oSelect As SelectEvents

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

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

        ' Create an InteractionEvents object.
        oInteraction = oAppOselect.CommandManager.CreateInteractionEvents

        ' Define that we want select events rather than mouse events.
        oInteraction.SelectionActive = True

        ' Set a reference to the select events.
        oSelect = oInteraction.SelectEvents

        ' Set the filter using the value passed in.
        oSelect.AddSelectionFilter(filter)

        ' The InteractionEvents object.
        oInteraction.Start()

        ' Loop until a selection is made.
        Do While bStillSelecting
            System.Windows.Forms.Application.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
        oSelectedEnts = oSelect.SelectedEntities
        If oSelectedEnts.Count > 0 Then
            Pick = oSelectedEnts.Item(1)
        Else
            Pick = Nothing
        End If

        ' Stop the InteractionEvents object.
        oInteraction.Stop()

        ' Clean up.
        oSelect = Nothing
        oInteraction = Nothing
    End Function

    Private Sub oSelect_OnSelect( _
        ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, _
        ByVal SelectionDevice As Inventor.SelectionDeviceEnum, _
        ByVal ModelPosition As Inventor.Point, _
        ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles oSelect.OnSelect
        bStillSelecting = False
    End Sub

End Class

 

0 Likes
Message 9 of 9

matt_jlt
Collaborator
Collaborator

Thankyou so much Wim. It finally works. I've spent so many hours trying to work out this problem i was starting to go a little crazy. Thanks again.

0 Likes