Has anyone had success implementing a select event which filters by point entities which allows users to select part edge midpoints? I have tried using kAllPointEntities and kPartEdgeMidpointFilter but I'm only able to select endpoints and not midpoints.
Actually the mid-point of a part edge is not a valid Inventor entity as the end-point. An end-point is recognized as Vertext object and can be selected, while the mid-point of an edge is exactly a position on the edge. So when you use the kPartEdgeMidpiontFilter in your interaction events, when your mouse hover on the mid-point of an edge, the whole edge would be highlighted, and after you selected it, you can check that (in the OnSelect event) the selected object (in JustSelectedEntities) is an Edge, and the mouse position (ModelPosition) should be at the mid-point of the edge.
Below sample demonstrates how the kPartEdgeMidpointFilter works (only when your mouse hover on the mid-point of an edge, the edge is selectable):
Copy below code to a module:
Public Sub SelectEdgeMidpoint() ' 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 the midpoint of edge. Dim oEdge As Edge Set oEdge = oSelect.Pick(kPartEdgeMidpointFilter) End Sub
Copy below code to a class module, and rename it as 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(filter As SelectionFilterEnum) As Object ' Initialize flag. bStillSelecting = True ' Create an InteractionEvents object. Set oInteraction = ThisApplication.CommandManager.CreateInteractionEvents ' Define that we want select events rather than mouse events. oInteraction.SelectionActive = True ' Set a reference to the select events. Set oSelect = oInteraction.SelectEvents ' Set the filter using the value passed in. oSelect.ClearSelectionFilter oSelect.AddSelectionFilter filter ' The InteractionEvents object. oInteraction.Start ' Loop until a selection is made. Do While bStillSelecting 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 = oSelect.SelectedEntities If oSelectedEnts.Count > 0 Then Set Pick = oSelectedEnts.Item(1) Else Set Pick = Nothing End If ' Stop the InteractionEvents object. oInteraction.Stop ' Clean up. Set oSelect = Nothing Set 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 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