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 Application Menu (File Browser Controls). In this post, let’s specifically add a Ribbon SplitButtonMRU to the Application Menu (File Browser Controls).
public void AddSplitButtonMRUToApplicationMenu()
{
UserInterfaceManager uiMan = AddinGlobal.InventorApp.UserInterfaceManager;
if (uiMan.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface)
{
Icon icon = new Icon(this.GetType(), "addin.ico"); // ICO embedded
InventorButton button1 = new InventorButton(
"Button 1", "INAW.InventorAddin.Presentation_ApplicationMenu_SplitButtonMRU1", "Button 1 description", "Button 1 tooltip",
icon, icon,
CommandTypesEnum.kShapeEditCmdType, ButtonDisplayEnum.kDisplayTextInLearningMode);
button1.Execute = () => MessageBox.Show("Hi, I'm SplitButtonMRU1."); // lambda expression.
InventorButton button2 = new InventorButton(
"Button 2", "INAW.InventorAddin.Presentation_ApplicationMenu_SplitButtonMRU2", "Button 2 description", "Button 2 tooltip",
icon, icon,
CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText);
button2.Execute = () => MessageBox.Show("Hi, I'm SplitButtonMRU2.");
ObjectCollection controls = AddinGlobal.InventorApp.TransientObjects.CreateObjectCollection();
controls.Add(button1.ButtonDef);
controls.Add(button2.ButtonDef);
AddinGlobal.InventorApp.UserInterfaceManager.FileBrowserControls.AddSplitButtonMRU(controls);
}
}
However, the code would throw out an exception if being tried in an Inventor addin:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.CommandControls.AddSplitButtonMRU(ObjectCollection ButtonDefinitions, Boolean UseLargeIcon, Boolean ShowText, String TargetControlInternalName, Boolean InsertBeforeTargetControl)
at ...
Since nothing wrong with the code, we could reach the conclusion that the Inventor Application Menu (File Browser Controls) does not support SplitButtonMRU type item.
We do not have an image this time since the SplitButtonMRU cannot be created into the Inventor Application Menu (File Browser Controls) at all.
The leading edge Inventor .NET Addin Wizard (InventorNetAddinWizard) can be found and downloaded from the A Wizard for Inventor .NET Addin page.
Posted by: |