New user-interface elements such as Marking Menus, Mini Toolbars, the Contextual Mini Toolbar and Balloon Tips were introduced in the Autodesk® Inventor® 2012 release. The Inventor 2012 API also provides access to all of this functionality so that you can incorporate them into your applications.
The post on March 2nd discussed how to create a mini toolbar. This time you see how to access marking menus. The following is a description of this VB.NET project that creates an Inventor Add-In. (This example was originally created by my colleague Philippe Leefsma).
First notice that there is a class named CMarkingMenu that contains all the code related to the marking menus:
For simplicity a toolbar is created when the Add-In is loaded by Inventor. This toolbar contains three buttons, each of the buttons allow activating or toggling the marking menus functionality without the need to customize the Ribbon.
Toggle Vertex Radial Menu
The first button is connected to the ToggleRadialMarkingMenu procedure. Pressing this button alternatively enables/disables the event handler for UserInputEvents.OnRadialMarkingMenu event.
Public Sub ToggleRadialMarkingMenu _
(ByVal Context As Inventor.NameValueMap)
_bRadialMarkingMenu = Not _bRadialMarkingMenu
If _bRadialMarkingMenu = False Then
AddHandler _UserInputEvents. _
OnRadialMarkingMenu, _
AddressOf OnRadialMarkingMenu
Else
RemoveHandler _UserInputEvents. _
OnRadialMarkingMenu, _
AddressOf OnRadialMarkingMenu
End If
End Sub
Private Sub OnRadialMarkingMenu _
(ByVal SelectedEntities As _
Inventor.ObjectsEnumerator, _
ByVal SelectionDevice As Inventor. _
SelectionDeviceEnum, _
ByVal RadialMenu As Inventor. _
RadialMarkingMenu, _
ByVal AdditionalInfo As _
Inventor.NameValueMap)
If SelectedEntities.Count <> 1 Then
Return
End If
If Not TypeOf SelectedEntities(1) _
Is Vertex Then
Return
End If
Dim subMenu As RadialMarkingMenu
subMenu = RadialMenu. _
CreateRadialSubMenu("Vertex Stuff")
subMenu.EastControl = _Application. _
CommandManager.ControlDefinitions _
("PartPointWorkPointCmd")
subMenu.WestControl = _Application. _
CommandManager.ControlDefinitions _
("AppSketch3DWrapperCmd")
RadialMenu.EastControl = subMenu
End Sub
As we can see in the code snippet, if a single vertex is selected at the time the user is right-clicking the mouse button, the event handler code replaces the RadialMarkingMenu.EastControl by a submenu containing two controls. Again, for simplicity, it uses two existing native controls, one creates a workpoint at the vertex location, the other creates a new sketch3d and sketchpoint3d in it.
Here’s a screenshot of the radial marking menu with the new menu “Vertex Stuff”. (Notice that a vertex is selected).
After selecting “Vertext Stuff” radial menu:
Activate Workpoint Radial Menu
The second button in the toolbar activates an object-specific marking menu. As illustrated in the snippet below, if a workpoint is currently selected, then a custom radial marking menu will be displayed upon right-click, which contains two commands.
This object-specific menu is environment dependant. It is not possible to rollback those changes inside a session, so if you want to restore the original marking menu for that kind of object, you would need to store the initial controls for each direction on the original RadialMarkingMenu returned by GetRadialMarkingMenu method.
Such override of the marking menu will also be reinitialized the next time you start Inventor, so if you want it to be persistent, your application will need to handle that customization each time it is loaded.
Public Sub ActivateRadialMarkingMenuCtx _
(ByVal Context As Inventor.NameValueMap)
Dim env As Environment = _Application _
.UserInterfaceManager.ActiveEnvironment
Dim radialMenu As RadialMarkingMenu
radialMenu = env.GetRadialMarkingMenu _
(ObjectTypeEnum.kWorkPointObject)
'Clear all of the buttons from the menu
' except for undo on the West and the
' East(button)
radialMenu.NorthControl = Nothing
radialMenu.NortheastControl = Nothing
radialMenu.NorthwestControl = Nothing
radialMenu.SouthControl = Nothing
radialMenu.SoutheastControl = Nothing
radialMenu.SouthwestControl = Nothing
'Redefine the East button with a
' new command.
radialMenu.EastControl = _Application _
.CommandManager.ControlDefinitions _
("AppMeasureDistanceCmd")
End Sub
Here is a screenshot of the result of selecting a workpoint and then doing a right-click:
Toggle Linear Menu
The third button on the toolbar illustrates the customization of the linear marking menu. This is also the old classic context menu. Note that the previous API is still working to customize that menu and was preserved in order to provide continued support for legacy code. You are encouraged to migrate your code to use the new API, as the old one will be retired at some point in the future.
Public Sub ToggleLinearMarkingMenu _
(ByVal Context As Inventor.NameValueMap)
_bLinearMarkingMenu = _
Not _bLinearMarkingMenu
If _bLinearMarkingMenu = False Then
AddHandler _UserInputEvents. _
OnLinearMarkingMenu, _
AddressOf OnLinearMarkingMenu
Else
RemoveHandler _UserInputEvents _
.OnLinearMarkingMenu, _
AddressOf OnLinearMarkingMenu
End If
End Sub
Private Sub OnLinearMarkingMenu _
(ByVal SelectedEntities As _
Inventor.ObjectsEnumerator, _
ByVal SelectionDevice As _
Inventor.SelectionDeviceEnum, _
ByVal LinearMenu As CommandControls, _
ByVal AdditionalInfo As _
Inventor.NameValueMap)
'Iterate each controls in linear menu
For Each ctrl As CommandControl _
In LinearMenu
' Uncomment to debug and see _
' results in output window
Debug.Print("Control: " + _
ctrl.DisplayName + _
" [" + ctrl.InternalName + "]")
'Inserts new button and separator in
' the linear menu
If (ctrl.InternalName = "AppHowToCmd") Then
LinearMenu.AddButton _
(_buttonDefRadialMarkingMenu, False, _
True, ctrl.InternalName, True)
LinearMenu.AddSeparator _
(ctrl.InternalName, True)
End If
Next
End Sub
In this event handler the “Toggle Vertex Radial Menu” button and a separator above the “AppHowToCmd” control are added as seen in this screenshot:
When you click this menu item the “Vertex Stuff” radial menu as described above is disabled or enabled.
I believe this VB.NET example will be very helpful if you are just getting started with this part of the API that allows you to incorporate radial marking menus in your application.
Wayne Brill


Subscribe