Add-in Shortcut Menus
To create and display a shortcut (pop-up) menu in a SolidWorks add-in, create
a SolidWorks C++, VB.NET, or C# add-in project in Visual Studio and do the
following:
-
In SwAddin.AddCommandManager():
-
Add a menu and menu item to the SolidWorks main menu by calling
ISldWorks::AddMenu
and
ISldWorks::AddMenuItem4 (C++ add-ins only).
When selected, the menu item will launch the shortcut menu.
-
Add a third-party
icon to a context-sensitive menu by calling
IFrame::AddMenuPopupIcon (C++
add-ins) or
IFrame::AddMenuPopupIcon2 (VB.NET
or C# add-ins).
When clicked, the icon will launch the shortcut menu.
-
Create and register your shortcut menu by
calling ISldWorks::RegisterThirdPartyPopupMenu.
-
Call
ISldWorks::AddItemToThirdPartyPopupMenu (C++
add-ins) or
ISldWorks::AddItemToThirdPartyPopupMenu2
(VB.NET or C# add-ins) one or more times to create one or more menu items in the
shortcut menu. Uniquely specify the item argument for each menu item,
menu break, and separator bar in the menu. Do not specify the item
argument for menu bar icons.
-
In the menu and toolbar callback region of SwAddin:
-
Implement the callback and enable functions
for each shortcut menu item and each menu bar icon that was created in
step 1d. See Add-in Callback and Enable
Methods.
-
Implement the callback and enable functions for the menu
item and third-party icon that were created in steps 1a and 1b. From the callback functions
of the icon and menu item, call
ISldWorks::ShowThirdPartyPopupMenu to display the shortcut menu at a specific
location in the SolidWorks graphics area. See
Add-in Callback and Enable Methods.
-
Remove menu items from the shortcut menu at runtime by calling
ISldWorks::RemoveItemFromThirdPartyPopupMenu from an event
handler of the add-in.
-
In SwAddin.DisconnectFromSW():
-
Call
ISldWorks::RemoveMenu to remove the menu from the SolidWorks main menu bar, if added in step
1a (C++ add-ins only).
-
Call
IFrame::RemoveMenuPopupIcon to remove the third-party icon from the context-sensitive menu, if
added in step 1b.
To learn more about add-ins and their menu items and toolbars: