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.
Solved by matt_jlt. Go to Solution.
Thanks cadull, I tried that but it does the same thing as the others, as soon as it gets to the DoEvents it gets stuck in the interaction. clicking the mouse doesn't do anything. I have to press escape to get out of it which cancels the command.
Hi Matt,
I understand VB has some auto event subscription based on the method name, but I don't know how this is configured or if you need to manually subscribe to the event in this case. In C#, we would add a line like:
oMouseEvents.OnMouseClick += oMouseEvents_OnMouseClick;
Regards,
cadull
Thanks cadull, i'll have to give that a go. I didn't even think about that. I'll add the event handler and see how it goes. If it works i'll post the final code here.
Regards, Matt.
All good, worked it out. Thanks for the help cadull. I had completely forgotton the event handler.
Just needed to add the following to the end of the mouse click sub.
Handles oMouseEvents.OnMouseClick
Regards, Matt.