CommandManager and CommandGroups
You can create native SOLIDWORKS toolbars and menus using the ICommandManager
and ICommandGroup
interfaces.
NOTE: You can only create one
CommandManager in an add-in application; however, multiple CommandGroups
can exist in an add-in application. See SOLIDWORKS Help for details about
the CommandManager.
The CommandManager-style toolbars and menus let you:
Add toolbars to the SOLIDWORKS CommandManager.
Drag your toolbar buttons to and from other API
and native SOLIDWORKS toolbars using the Tools,
Customize dialog or ISldWorks::DragToolbarButton.
Create flyout toolbars and submenus.
Toolbar and menu setup are binded so that name, button, callback function,
enable function, and add-in ID need only be specified once.
You cannot create a ICommandGroup with a toolbar, start SOLIDWORKS,
use the toolbar, close SOLIDWORKS, add items to or remove items from the
toolbar, and start SOLIDWORKS. Therefore, during development, you must
use the ID returned by ICommandGroup::ToolbarId
to find the toolbar in the registry and remove the toolbar definition
from the registry:
HKEY_CURRENT_USER\Software\SOLIDWORKS\SOLIDWORKS
<version>\User Interface\Custom API Toolbars\<index>
HKEY_CURRENT_USER\Software\SOLIDWORKS\SOLIDWORKS
<version>\User Interface\Toolbars
HKEY_CURRENT_USER\Software\SOLIDWORKS\SOLIDWORKS
<version>\User Interface\Toolbars\PartTool
HKEY_CURRENT_USER\Software\SOLIDWORKS\SOLIDWORKS
<version>\User Interface\Toolbars\AssemblyTool
HKEY_CURRENT_USER\Software\SOLIDWORKS\SOLIDWORKS
<version>\User Interface\Toolbars\DrawingTool
You can then add and remove items from the toolbar.
For distribution purposes, assign the ICommandGroup a different user
ID and do not activate the ICommandGroup using the former user ID. This
is the ID of ICommandManager::CreateCommandGroup.
You must keep track of the toolbar user IDs in use in each version of
your add-in. The user ID and the GUID of the CoClass implementing ISwAddin
are a unique pair.
To add commands:
Create the ICommandManager using ISldWorks::GetCommandManager.
NOTE: You might want to declare this object as a class variable
in your add-in so that it can be accessed from anywhere later.
Create one or more top-level CommandGroups using
ICommandManager::CreateCommandGroup
or ICommandManager::AddContextMenu.
Add bitmap files of the images of buttons to the
CommandGroups using ICommandGroup::LargeIconList,
ICommandGroup::SmallIconList,
ICommandGroup::LargeMainIcon,
and ICommandGroup::SmallMainIcon.
NOTE: You only add the bitmap files to the top-level group.
These files provide the images of the buttons for all of the CommandGroups.
Add commands to the CommandGroups using ICommandGroup::AddCommandItem2.
Enable or disable toolbars or menus for specific
CommandGroups using ICommandGroup::HasToolbar
and ICommandGroup::HasMenu.
Create context-sensitive menus using ICommandGroup::SelectType
and ICommandGroup::CustomNames,
if the selected object is a custom feature such as an attribute.
Activate the top-level ICommandGroup using ICommandGroup::Activate.
To remove commands:
Use ICommandManager::RemoveCommandGroup
for all CommandGroups created with ICommandManager::CreateCommandGroup
and ICommandManager::AddContextMenu.