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