Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
C_Haines_ENG
159 Views, 4 Replies

EventHandlers Glitching Inventor - Cant Edit Sketches / Open Components

Good Morning everyone,

 

I have actually had this issue for quite a while, but Interaction events / Event Handles are causing my Inventor to stop functioning properly. See my code below:

 

Sub Main

	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oSelect As New oSelectClass
	
	oSelect.Pick(ThisApplication)
	
	If oSelect.oFrame Is Nothing Then Exit Sub

	Logger.Info(oSelect.oFrame.Name)
	Logger.Info(oSelect.oModelPoint.X)
	
End Sub

Class oSelectClass

	Private WithEvents oInteractEvents As InteractionEvents
	Private WithEvents oSelectEvents As SelectEvents

	Public oFrame As ComponentOccurrence
	Public oModelPoint As Point

	Public Sub Pick(oApp As Inventor.Application)

		oInteractEvents = oApp.CommandManager.CreateInteractionEvents
		oInteractEvents.StatusBarText = "SELECT FRAME, ESC TO EXIT"

		oSelectEvents = oInteractEvents.SelectEvents
		oSelectEvents.AddSelectionFilter(kAssemblyLeafOccurrenceFilter)

		oInteractEvents.Start() : AppActivate(oApp.Caption)

		Do While oFrame Is Nothing
			oApp.UserInterfaceManager.DoEvents
		Loop
		
		oInteractEvents.Stop : oApp.CommandManager.StopActiveCommand

		oSelectEvents = Nothing : oInteractEvents = Nothing

	End Sub

	Private Sub oSelectEvents_OnSelect(oFrames, oDevice, oPoint, oView2D, oView) Handles oSelectEvents.OnSelect
		oFrame = oFrames(1)
		oModelPoint = oPoint
	End Sub

End Class  

 I suspect it has something to do with Interaction events not actually "stopping" when using InteractionEvents.Stop. It causes other interaction events such as editing a sketch to not allow you to change anything, and having the "save sketch" feature greyed out, or being unable to select a component occurrence to open it individually. 

 

If anyone knows anything about this and could fix my nightmare, that would be appreciated.  While "oApp.CommandManager.StopActiveCommand" does exit you out, it seems to have more consequences than I thought. 

 

To test this issue, simply run the command a few times, maybe click on items in an assembly. Then try to edit a sketch and see how it doesn't work anymore! This could also have something to do with loops but I doubt it.