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.
In these series, we are going to look at the Ribbon Quick Access Toolbar (QAT). In this post, let’s specifically add a Ribbon TogglePopup to the Quick Access Toolbar (QAT).
public void AddTogglePopupToQAT()
{
UserInterfaceManager uiMan = AddinGlobal.InventorApp.UserInterfaceManager;
if (uiMan.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface)
{
Ribbon ribbon = uiMan.Ribbons["Presentation"];
Icon icon = new Icon(this.GetType(), "addin.ico"); // ICO embedded
ButtonDefinition button1 = CreateButtonDefinition(
"Button 1", "INAW.InventorAddin.Presentation_QAT_TogglePopup1", "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_QAT_TogglePopup2", "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;
ObjectCollection controls = AddinGlobal.InventorApp.TransientObjects.CreateObjectCollection();
controls.Add(button1);
controls.Add(button2);
ribbon.QuickAccessControls.AddTogglePopup(button1, controls);
}
}
As can be seen, the key point is to get the Ribbon Quick Access Toolbar (QAT) from the Ribbon of the Environment such as the ‘Presentation’ here. Then adding a TogglePopup to the Ribbon Quick Access Toolbar (QAT) is pretty much the same as doing so to a Ribbon Panel that we have demonstrated many times.
Here is what the TogglePopup looks like in the Ribbon Quick Access Toolbar (QAT):
The leading edge Inventor .NET Addin Wizard (InventorNetAddinWizard) can be found and downloaded from the A Wizard for Inventor .NET Addin page.
Posted by: |