I'm trying to add a dropdown menu to my right-click menu but I'm at a loss.
I'm looking to take the "Laser, Mill, Sol's" commands and put them in a flyout menu exactly like the BOM Structure commands.
I thought it might have just been using the "AddButtonPopup" function but that throws an error when I tried to add an object collection of those 3 button definitions. Not sure that style button can't be added to the context menu of if I messed up the function somehow.
Solved! Go to Solution.
Solved by yuzeaa. Go to Solution.
Still getting an error when I do it the way described in that post, happens when right-click and it tries to add the controls to the command bar. I even downloaded the .rar to look through that code and mine is functionally identical for all I can tell (My buttons are defined elsewhere and put into a 'contextButtons' list)
AddHandler m_inventorApplication.CommandManager.UserInputEvents.OnContextMenu,
Sub(SelectionDevice As Inventor.SelectionDeviceEnum, AdditionalInfo As Inventor.NameValueMap, CommandBar As Inventor.CommandBar)
If m_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim SelectedEntities As SelectSet = m_inventorApplication.ActiveDocument.SelectSet
If SelectedEntities.Count > 0 Then
If TypeOf SelectedEntities(1) Is ComponentOccurrence Then
Dim CategoryButtons As CommandBar = m_inventorApplication.UserInterfaceManager.CommandBars.Add("Category", "CategoryCmd", CommandBarTypeEnum.kButtonPopupCommandBar)
CategoryButtons.Controls.AddButton(contextButtons("Laser"))
CategoryButtons.Controls.AddButton(contextButtons("Mill"))
CategoryButtons.Controls.AddButton(contextButtons("Sol's"))
CommandBar.Controls.AddPopup(CategoryButtons)
End If
End If
End If
End Sub
you can't define commandbar with same internalname everytime rightclick.
Class ThisRule
Dim contextButtons As New Dictionary(Of String,ButtonDefinition)
Private CategoryButtons As CommandBar
Sub main
Dim oControls = ThisApplication.CommandManager.ControlDefinitions
contextButtons.Add("Laser", oControls.AddButtonDefinition("Laser", "LaserCmd", CommandTypesEnum.kShapeEditCmdType))
contextButtons.Add("Mill", oControls.AddButtonDefinition("Mill", "MillCmd", CommandTypesEnum.kShapeEditCmdType))
contextButtons.Add("Sol's", oControls.AddButtonDefinition("Sol's", "Sol'sCmd", CommandTypesEnum.kShapeEditCmdType))
CategoryButtons =ThisApplication.UserInterfaceManager.CommandBars.Add("Category", "CategoryCmd", CommandBarTypeEnum.kPopUpCommandBar)
CategoryButtons.Controls.AddButton(contextButtons("Laser"))
CategoryButtons.Controls.AddButton(contextButtons("Mill"))
CategoryButtons.Controls.AddButton(contextButtons("Sol's"))
AddHandler ThisApplication.CommandManager.UserInputEvents.OnContextMenu, AddressOf OnContextMenu
End Sub
Private Sub OnContextMenu(SelectionDevice As SelectionDeviceEnum, AdditionalInfo As NameValueMap, CommandBar As CommandBar)
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim SelectedEntities As SelectSet = ThisApplication.ActiveDocument.SelectSet
If SelectedEntities.Count > 0 Then
If TypeOf SelectedEntities(1) Is ComponentOccurrence Then
CommandBar.Controls.AddPopup(CategoryButtons)
End If
End If
End If
End Sub
End Class
Can't find what you're looking for? Ask the community or share your knowledge.