Message 1 of 6
Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.CreateInteractionEvents ' 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