蒹葭苍苍,白露为霜。
所谓伊人,在水一方。

inventor开发之事件案例1

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

 

 

赞(0) 打赏
未经允许不得转载:酷居科技 » inventor开发之事件案例1

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

锦瑟无端五十弦,一弦一柱思华年

酷居科技联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏