The Inventor API has provided the Ribbon API for some time. We can use the Inventor Ribbon API to access to those existing Ribbon UI elements such as Ribbon Environment, Ribbon Tab, Ribbon Panel, Ribbon Button, Various Ribbon Controls, and so on.
We can also create various Inventor ribbon buttons, controls, panels, and tabs. In this post, let’s create a Ribbon Toggle Popup into an existing ribbon panel.
public void CreateRibbonTogglePopup()
{
UserInterfaceManager uiMan = AddinGlobal.InventorApp.UserInterfaceManager;
if (uiMan.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface)
{
RibbonTab tab = GetSetRibbonTab("Presentation", "INAW", null);
RibbonPanel panel = GetSetRibbonPanel(tab, "INAW Panel07", null);
Icon icon = new Icon(this.GetType(), "addin.ico"); // ICO embedded
ButtonDefinition button0 = CreateButtonDefinition(
"TogglePopup", "INAW.InventorAddin.Presentation_INAW_INAWPanel07_BigButton0", "TogglePopup description", "TogglePopup tooltip",
icon, icon,
CommandTypesEnum.kShapeEditCmdType, ButtonDisplayEnum.kDisplayTextInLearningMode);
ButtonDefinition button1 = CreateButtonDefinition(
"Button 1", "INAW.InventorAddin.Presentation_INAW_INAWPanel07_BigButton1", "Button 1 description", "Button 1 tooltip",
icon, icon,
CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText);
button1.Enabled = true;
button1.Pressed = false;
button1.OnExecute += (NameValueMap Context) => button1.Pressed = !button1.Pressed;
ButtonDefinition button2 = CreateButtonDefinition(
"Button 2", "INAW.InventorAddin.Presentation_INAW_INAWPanel07_BigButton2", "Button 2 description", "Button 2 tooltip",
icon, icon,
CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText);
button2.Enabled = true;
button2.Pressed = true;
button2.OnExecute += (NameValueMap Context) => button2.Pressed = !button2.Pressed;
ButtonDefinition button3 = CreateButtonDefinition(
"Button 3", "INAW.InventorAddin.Presentation_INAW_INAWPanel07_BigButton3", "Button 3 description", "Button 3 tooltip",
icon, icon,
CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText);
button3.Enabled = true;
button3.Pressed = false;
button3.OnExecute += (NameValueMap Context) => button3.Pressed = !button3.Pressed;
ObjectCollection controls = AddinGlobal.InventorApp.TransientObjects.CreateObjectCollection();
controls.Add(button1);
controls.Add(button2);
controls.Add(button3);
CommandControls cmdCtrls = panel.CommandControls;
cmdCtrls.AddTogglePopup(button0, controls, true, true, "", false);
}
}
public static ButtonDefinition CreateButtonDefinition(
string displayName, string internalName, string description, string tooltip,
Icon standardIcon, Icon largeIcon,
CommandTypesEnum commandType, ButtonDisplayEnum buttonDisplayType)
{
stdole.IPictureDisp standardIconIPictureDisp = null;
stdole.IPictureDisp largeIconIPictureDisp = null;
if (standardIcon != null)
{
standardIconIPictureDisp = (stdole.IPictureDisp)Microsoft.VisualBasic.Compatibility.VB6.Support.IconToIPicture(standardIcon);
largeIconIPictureDisp = (stdole.IPictureDisp)Microsoft.VisualBasic.Compatibility.VB6.Support.IconToIPicture(largeIcon);
}
return AddinGlobal.InventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(
displayName, internalName, commandType,
Guid.NewGuid().ToString(), description, tooltip,
standardIconIPictureDisp, largeIconIPictureDisp, buttonDisplayType);
}
After the code is run, a Ribbon Toggle Popup along with three ribbon toggle buttons in it will be created and added into the ribbon panel ‘INAW Panel07’ under the INAW ribbon tab that we created before into the ‘Presentation’ ribbon environment.
It may look similar to some other button types such as big button, ribbon popup, button popup, split button, and MRU split button, but does have its own behavior. Here is what has been observed about the Toggle Popup.
• It has two parts, icon and text along with a small down arrow.
• There is no split line in between the icon and the text/arrow.
• Click the Toggle Popup will pull it down.
• The Toggle Popup can have its own icon and text/description and tooltip.
• The status of toggle buttons will not be toggled automatically. We have to subscribe to the OnExecute event and change the status of the Enabled and Pressed ourselves.
• Only the button text/description will show up. The icon of each toggle button will disappear but a check box will appear instead on the left.
• The actions of the toggle buttons should be taken care of differently than command buttons.
The leading edge Inventor .NET Addin Wizard (InventorNetAddinWizard) can be found and downloaded from the A Wizard for Inventor .NET Addin page.
Posted by: |