Files
Code
Module: mMain
'Demonstrates how to listen for mouse events.
'Precondition: document is open
'Result: when an item is selected in the display area, window space coordinates and _
model space coordinates are printed to the immediate window
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim listener As New MouseListener
Sub main()
listener.connect
End Sub
Class: MouseListener
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelView As SldWorks.ModelView
Dim WithEvents swMouse As SldWorks.Mouse
Public Sub connect()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then End
Set swModelView = swModel.ActiveView
Set swMouse = swModelView.GetMouse
End Sub
Private Function swMouse_MouseSelectNotify(ByVal Ix As Long, ByVal Iy As Long, ByVal X As Double, ByVal Y As Double, ByVal Z As Double) As Long
Debug.Print "Window space coords: " & Round(Ix, 6) & ", " & Round(Iy, 6)
Debug.Print "Model space coords: " & Round(X, 6) & ", " & Round(Y, 6) & ", " & Round(Z, 6)
End Function