I have a macro that I used to get XY points on a drawing sheet in order to place items. Now that I am on 64bit 2012, it still functions, but it is very erratic and I have to get it to work by clicking the mouse repeatedly and much harder than usual. Eventually it takes and my symbol is placed! The crosshair cursor also blinks in and out during this time also. I am not selecting anything in the drawing, I just want to click on a blank area and get the drawing coordinates like I used to in previous versions. Wondering if there is some new method to get the mouse click and underlying xy point in 2012? Here is the code I have been using:
'class module clsGetPoint2D Option Explicit Public X As Double, Y As Double, Z As Double Public JustifyRight As Boolean ' Declare the event objects Private WithEvents oInteractEvents As InteractionEvents Private WithEvents oMouseEvents As Inventor.MouseEvents ' Declare a flag that's used to determine when selection stops. Private bStillSelecting As Boolean __________________________________________________
_____________ Public Function GetPoint() As Point ' Initialize flag. bStillSelecting = True ' Create an InteractionEvents object. Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEv ents ' Define that we want mouse events rather than select events. oInteractEvents.SelectionActive = False oInteractEvents.StatusBarText = "Click mouse for 2D location" oInteractEvents.SetCursor (kCursorBuiltInCrosshair) ' Set a reference to the mouse events. Set oMouseEvents = oInteractEvents.MouseEvents 'Don't need move events oMouseEvents.MouseMoveEnabled = False ' Start the InteractionEvents object. oInteractEvents.Start ' Loop until a (2D) point in the IDW is selected. Do While bStillSelecting ThisApplication.UserInterfaceManager.DoEvents Loop ' Stop the InteractionEvents object. oInteractEvents.Stop ' Clean up. Set oMouseEvents = Nothing Set oInteractEvents = Nothing End Function __________________________________________________ ___ Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) X = ModelPosition.X Y = ModelPosition.Y Z = ModelPosition.Z bStillSelecting = False End Sub
I have noticed today that if I slowly pan the drawing with my spacepilot while this macro is running, then the mouse clicking and cursor are not erratic anymore and I can place my symbols and leaders from the macro much easier. Since I am using an outdated spacepilot driver which I cannot update unless I buy a new, supported device, for now I will just have to assume this is a bug caused by the spaceball drivers in Inventor? It would be nice if there was someway to programatically ignore the spaceball in VBA to avoid this issue perhaps? Still would be willing to look at new methods of getting the sheet position of a mouse click also.
I want to use this code to get the coördinates of a point2D in a drawing view. But I can't get it to work.
I use Inventor 2013.
Can you help me on how to implement this code?
The code I posted is simply for a class module. You need to have macro code elsewhere that calls this class module. Simplest case, something like:
Dim oGetPoint2D As New clsGetPoint2D
MsgBox "X = " & oGetPoint2D.X & vbNewLine & "Y = " & oGetPoint2D.Y
I don't have 2013, but it should still work unless they made some drastic changes?
Happy New Year!
One thing I would try is avoiding DoEvents and lets see if that helps:
' members Private WithEvents oInteractionEvents As InteractionEvents Private WithEvents oMouseEvents As MouseEvents Public Sub StartInteraction() Set oInteractionEvents = ThisApplication.CommandManager.CreateInteractionEv
ents() ' subscribe to receive mouse events Set oMouseEvents = oInteractionEvents.MouseEvents oInteractionEvents.SelectionActive = False ' start interaction Call oInteractionEvents.Start End Sub Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Set oMouseEvents = Nothing Set oInteractionEvents = Nothing End Sub Private Sub oInteractionEvents_OnTerminate() ' Nothing got selected - the user started another ' command or just cancelled this interaction Set oMouseEvents = Nothing Set oInteractionEvents = Nothing End Sub
Dim cls1 As Class1 Sub CheckInteractionEvents() Set cls1 = New Class1 Call cls1.StartInteraction End Sub
I will have to try that when I get a chance! I had wanted to switch to using CommandManager.Pick instead, but could find no way to use it to just capture a mouse click without actually picking anything.