By Adam Nagy
You can add items to the context menu inside the OnLinearMarkingMenu event handler. This also provides the list of currently selected entities. You can easily check if they are of a given entity type or not - e.g. if they are Ordinate Dimensions - and based on that decide if we add our own control definition or not.
This VBA sample shows how to do it. When the class (I named it clsLinearMarkingMenu) is initialized the Class_Initialize function is called and there we check if our control definition has already been registered. If not, then we create it and register it. Inside the OnExecute event handler of our control definition we can do the operation we want when our control (context menu item in this case) is clicked. In this case we'll add a plus sign to the dimension text.
Class clsLinearMarkingMenu:
Dim WithEvents uie As UserInputEvents Dim WithEvents bd1 As ButtonDefinition Private Sub bd1_OnExecute(ByVal Context As NameValueMap) Dim ss As SelectSet Set ss = ThisApplication.ActiveDocument.SelectSet Dim ordDim As OrdinateDimension For Each ordDim In ss ' Change the text of the selected ordinate dimensions ordDim.Text.FormattedText = _ ordDim.Text.FormattedText + "+" Next End Sub Private Sub Class_Initialize() Dim cm As CommandManager Set cm = ThisApplication.CommandManager Set uie = cm.UserInputEvents ' Make sure our control is available On Error Resume Next Set bd1 = cm.ControlDefinitions("DimTextPlus") If bd1 Is Nothing Then Set bd1 = cm.ControlDefinitions.AddButtonDefinition( _ "Dim Text +", "DimTextPlus", kNonShapeEditCmdType) End If End Sub Function AreAllOrdinate(entities As ObjectsEnumerator) As Boolean Dim entity As Object For Each entity In entities If Not TypeOf entity Is OrdinateDimension Then AreAllOrdinate = False Exit Function End If Next AreAllOrdinate = True End Function Private Sub uie_OnLinearMarkingMenu( _ ByVal SelectedEntities As ObjectsEnumerator, _ ByVal SelectionDevice As SelectionDeviceEnum, _ ByVal LinearMenu As CommandControls, _ ByVal AdditionalInfo As NameValueMap) ' We only add our context menu item if the ' selected entities are all ordinate dimensions If AreAllOrdinate(SelectedEntities) Then Call LinearMenu.AddButton(bd1) End If End Sub
Then we can instantiate our class in any of the Modules:
Dim lmm As clsLinearMarkingMenu Sub TestLinearMarkingMenu() Set lmm = New clsLinearMarkingMenu End Sub
Now when we right-click on an ordinate dimension our menu item will show up: