Message 1 of 4
Get ShiftStateEnum during a Select Event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Inventor 2021, latest version:
Here's a sample of a rule I'm working on. When a user selects an occurrence an assembly, I want something different to happen if they select it while holding down Shift. I've tried just tracking this with an If Then statement controlling a boolean in a Mouse Event subroutine, but this doesn't seem to take effect during a Select event.
In this sample rule, select an assembly occurrence with either the shift key pressed or not and a messagebox should confirm it if there's a way to make it work, otherwise press Esc to exit the rule:
Class ThisRule Dim bStop As Boolean = False Dim bShift As Boolean = False Dim oApp As Inventor.Application Dim oDoc As Document Dim oComMgr As CommandManager Private WithEvents evInteractionEvents As InteractionEvents Private WithEvents evSelectEvents As SelectEvents Private WithEvents evKeyboardEvents As KeyboardEvents Private WithEvents evMouseEvents As MouseEvents Sub Main oApp = ThisApplication oDoc = ThisDoc.Document If TypeOf oDoc Is AssemblyDocument And Right(oApp.UserInterfaceManager.ActiveEnvironment.DisplayName, 8) = "Assembly" Then oComMgr = oApp.CommandManager evInteractionEvents = oComMgr.CreateInteractionEvents evSelectEvents = evInteractionEvents.SelectEvents evSelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter) evSelectEvents.WindowSelectEnabled = False evSelectEvents.Enabled = True evInteractionEvents.Start Do oApp.UserInterfaceManager.DoEvents Loop Until bStop = True evInteractionEvents.Stop Else MessageBox.Show("This rule must be run in an Assembly Environment.") End If End Sub Sub evKeyboardEvents_OnKeyPress(lKey As Long) Handles evKeyboardEvents.OnKeyPress If lKey = 27 Then bStop = True End Sub Sub evSelectEvents_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As ObjectCollection, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnPreSelect PreSelectEntity = PreSelectEntity.OccurrencePath.Item(1) DoHighlight = True End Sub Sub evMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles evMouseEvents.OnMouseClick If ShiftKeys = ShiftStateEnum.kShiftStateShift Then bShift = True Else bShift = False End If End Sub Sub evSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnSelect oEntity = JustSelectedEntities.Item(1) If Shift = True Then MessageBox.Show("Shift Key") Else MessageBox.Show("No Shift Key") End If End Sub End Class
Thanks for your help.