SelectionFilterEnum for holes

SelectionFilterEnum for holes

waynehelley
Collaborator Collaborator
359 Views
3 Replies
Message 1 of 4

SelectionFilterEnum for holes

waynehelley
Collaborator
Collaborator

Hello,

 

Does anybody know if there is a SelectionFilterEnum option that will behave like the Hole creation tool.

 

i.e. similar to 'kPartFaceFilter' but I also need to know the co-ordinates of where the the user clicked.

 

SelectionFilterEnum.PNG

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
0 Likes
Accepted solutions (1)
360 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

I don't know if this is what you are looking for but the selector class lets you select a face and returns the face and the point on the face you selected. Anyway, have a look at this rule. It will create a hole in the face in the position that you clicked.

Public Class ThisRule

    Sub Main()


        Dim selector As New Selector(ThisApplication)
        selector.Pick()

        Dim doc As PartDocument = ThisDoc.Document
        Dim def As PartComponentDefinition = doc.ComponentDefinition

        Dim sketch As PlanarSketch = def.Sketches.Add(selector.SelectedFace)

        Dim point2d As Point2d = sketch.ModelToSketchSpace(selector.ModelPosition)

        Dim circleRadius = 0.5 ' in Cm!
        sketch.SketchCircles.AddByCenterRadius(point2d, circleRadius)
        Dim profile = sketch.Profiles.AddForSolid()


        Dim exturdDef = def.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kCutOperation)
        exturdDef.SetDistanceExtent(10, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
        def.Features.ExtrudeFeatures.Add(exturdDef)

    End Sub
End Class

Public Class Selector

    Private WithEvents _interactEvents As InteractionEvents
    Private WithEvents _selectEvents As SelectEvents
    Private _stillSelecting As Boolean
    Private _inventor As Inventor.Application

    Public Sub New(ThisApplication As Inventor.Application)
        _inventor = ThisApplication
    End Sub

    Public Sub Pick()
        _stillSelecting = True

        _interactEvents = _inventor.CommandManager.CreateInteractionEvents
        _interactEvents.InteractionDisabled = False
        _interactEvents.StatusBarText = "Select point on face."
        _interactEvents.SetCursor(CursorTypeEnum.kCursorBuiltInCrosshair)

        _selectEvents = _interactEvents.SelectEvents
        _selectEvents.WindowSelectEnabled = False

        _interactEvents.Start()
        Do While _stillSelecting
            _inventor.UserInterfaceManager.DoEvents()
        Loop
        _interactEvents.Stop()

        _inventor.CommandManager.StopActiveCommand()

    End Sub

    Public Property SelectedFace As Object = Nothing
    Public Property ModelPosition As Point = Nothing

    Private Sub oSelectEvents_OnPreSelect(
            ByRef PreSelectEntity As Object,
            ByRef DoHighlight As Boolean,
            ByRef MorePreSelectEntities As ObjectCollection,
            SelectionDevice As SelectionDeviceEnum,
            ModelPosition As Point,
            ViewPosition As Point2d,
            View As Inventor.View) Handles _selectEvents.OnPreSelect

        DoHighlight = False

        If (not TypeOf PreSelectEntity Is Face) Then Return

        Dim face As Face = PreSelectEntity

        If (face.SurfaceType <> SurfaceTypeEnum.kPlaneSurface) Then Return

        DoHighlight = True

    End Sub

    Private Sub oInteractEvents_OnTerminate() Handles _interactEvents.OnTerminate
        _stillSelecting = 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) Handles _selectEvents.OnSelect

        SelectedFace = JustSelectedEntities.Item(1)
        Me.ModelPosition = ModelPosition


        _stillSelecting = False
    End Sub
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

dg2405
Advocate
Advocate

Hey Jelte,

is it possible so select an edge while beeing in an acitve sketch. Whether with the CommanManager.Pick-Method nor with your interaction-events method here it's not possible to pick an edge while beeing in an active sketch.

0 Likes
Message 4 of 4

dg2405
Advocate
Advocate

I forgot to mention that this problem is only specific when selecting an edge of the same part where the sketch is acitve.

0 Likes