Imports Inventor
Public Class MouseEventChecker
Private WithEvents oUserInputEvents As UserInputEvents
Private oIE As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents
Private Occ As ComponentOccurrence
Private Plane As Plane
Public Sub Initialize(_occ As ComponentOccurrence, _Plane As Plane)
Occ = _occ
Plane = _Plane
oUserInputEvents = Inv.App.CommandManager.UserInputEvents
oIE = Inv.App.CommandManager.CreateInteractionEvents
oMouseEvents = oIE.MouseEvents
oMouseEvents.MouseMoveEnabled = True
oIntGraphics = oIE.InteractionGraphics
oIE.SetCursor(CursorTypeEnum.kCursorBuiltInCommonSketchDrag)
oIE.Start()
End Sub
Private Sub oMouseEvents_OnMouseMove(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oMouseEvents.OnMouseMove
Dim oCamera As Inventor.Camera = Inv.App.ActiveView.Camera
Dim oVec As Vector = oCamera.Eye.VectorTo(oCamera.Target)
Dim oTG As TransientGeometry = Inv.App.TransientGeometry
Dim oLine As Line = oTG.CreateLine(ModelPosition, oVec)
Dim ProjectedPoint As Point = Plane.IntersectWithLine(oLine)
Dim matrix As Matrix = Occ.Transformation
matrix.Cell(1, 4) = ProjectedPoint.X
matrix.Cell(2, 4) = ProjectedPoint.Y
matrix.Cell(3, 4) = ProjectedPoint.Z
Occ.Transformation = matrix
oIE.Stop()
End Sub
End Class
This is the code that works based on the ondrag example, but instead you need to give an occurrence (you just placed) and a plane (not workplane)
The onMouseMove event is just triggered once to get Modelposition as point (which is mouse cursor point in 3d space)