Inventor Customization

Active Member
Posts: 7
Registered: ‎09-11-2008
Message 1 of 2 (410 Views)

Midpoint selection filter

410 Views, 1 Replies
07-12-2010 07:44 AM

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.

Posts: 477
Registered: ‎01-06-2009
Message 2 of 2 (389 Views)

Re: Midpoint selection filter

07-13-2010 12:57 AM in reply to: mbair

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.AddSelectionFilter filter
    ' The InteractionEvents object.
    ' Loop until a selection is made.
    Do While bStillSelecting
    ' 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)
        Set Pick = Nothing
    End If
    ' Stop the InteractionEvents object.
    ' 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



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.