Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a simple selection class I have been using successfully as a macro for a long time. I tried converting it to an addin but have hit a speed bump with 'DoEvents'. It doesn't work at all in an addin. If anyone could help me sort this out it would be great. I inserted all of the relevant code below.
Thanks, Matt.
I have tried the following in place of the DoEvents
Application.DoEvents
ThisApplication.DoEvents
System.Windows.Forms.Application.DoEvents
Below is a section of the module code to initialise selection
' Get user input for mouse position on click Dim oGetPoint As New clsSelectPoint Dim oCP As Point2d = oGetPoint.GetPoint
Below is the select class
Public Class clsSelectPoint ' Declare the event objects Private WithEvents oInteraction As InteractionEvents Private WithEvents oMouseEvents As MouseEvents ' Declare a flag that's used to determine when selection stops. Private bStillSelecting As Boolean Private oSelectedPoint As Inventor.Point2d Public Function GetPoint() As Inventor.Point2d ' Initialize flag. bStillSelecting = True ' Create an InteractionEvents object. oInteraction = ThisApplication.CommandManager.CreateInteractionEvents() ' Set a reference to the mouse events. oMouseEvents = oInteraction.MouseEvents ' Disable mouse move since we only need the click. oMouseEvents.MouseMoveEnabled = False ' The InteractionEvents object. oInteraction.Start() ' Loop until a selection is made. Do While bStillSelecting 'DoEvents ' ############# This is where the issue is Loop ' Set the return variable with the point. GetPoint = oSelectedPoint ' Stop the InteractionEvents object. oInteraction.Stop() ' Clean up. oMouseEvents = Nothing oInteraction = Nothing End Function Private Sub oInteraction_OnTerminate() ' Set the flag to indicate we're done. bStillSelecting = False End Sub Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) 'oSelectedPoint = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y) ' Temporarily commented out bStillSelecting = False MessageBox.Show("mouse pressed") End Sub End Class
Solved! Go to Solution.