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 Inventor.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
Public Sub ShowSurfaceArea2()
' 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 oFace As Face
oFace = oSelect.Pick(SelectionFilterEnum.kPartFaceFilter, _invApp)
' Check to make sure a face was selected.
If Not oFace Is Nothing Then
' Display the area of the selected face.
MsgBox("Surface area: " & oFace.Evaluator.Area & " cm^2")
End If
End Sub