Add Custom Panel and Button to Built-in Tab of Navisworks Ribbon

By Xiaodong Liang

As we have known, Naivisworks Ribbon API allows developers to add custom Ribbon (Tab) . These are some articles:

http://adndevblog.typepad.com/aec/2012/07/custom-ribbon-of-navisworks-part-1.html

http://adndevblog.typepad.com/aec/2012/07/custom-ribbon-of-navisworks-part-2.html

http://adndevblog.typepad.com/aec/2012/07/custom-ribbon-of-navisworks-part-3.html

While sometimes, the requirement is to add button/panel to the built-in tabs. Actually, in  Navisworks the same library of Ribbon is used: AdWindows.dll which provides some underlying API to get access to that notification under the namespace Autodesk.Windows. We have had some articles for such as Inventor, Revit

http://adndevblog.typepad.com/manufacturing/2013/02/intercept-click-event-on-a-ribbon-tab.html

http://adndevblog.typepad.com/manufacturing/2014/01/modify-ribbon-and-menu-items.html

http://adndevblog.typepad.com/manufacturing/2013/02/intercept-click-event-on-a-ribbon-tab.html

Note: AdWindows APIs are not a section of the official APIs, though you can access it at your own risk.

Based on the ideas, I made some codes in a custom plugin as below. It will add a new panel to the built-in tab [Home], and a button named [ADN Test]. When the tab is activated, a message box will appear. The same when the button is clicked.

The resource codes is available at Download ADNTestBuiltInRibbon. It is tested in Navisworks 2016. The only issue I hit is sometimes the image does not appear. I will update this blog when I figured out.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
//Add two new namespaces
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using Autodesk.Windows;
namespace BasicPlugIn
{
[PluginAttribute("BasicPlugIn.ABasicPlugin",                   //Plugin name
"ADSK",                                       //4 character Developer ID or GUID
ToolTip = "BasicPlugIn.ABasicPlugin tool tip",//The tooltip for the item in the ribbon
DisplayName = "Hello World Plugin")]          //Display name for the Plugin in the Ribbon
public class ABasicPlugin : AddInPlugin                        //Derives from AddInPlugin
{
// when the tab is activated
void Tab_Activated(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show(
"Tab " + ComponentManager.Ribbon.ActiveTab.Id + " Activated!");
}
//delegate the event when ribbon element is activated
void ComponentManager_UIElementActivated(object sender,UIElementActivatedEventArgs e)
{
if (e != null
&& e.Item != null
&& e.Item.Id != null
&& e.Item.Id == "ID_ADNTestButton")
{
System.Windows.Forms.MessageBox.Show(e.Item.Id + " is clicked!");
}
}
public override int Execute(params string[] parameters)
{
foreach (Autodesk.Windows.RibbonTab Tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs)
{
//get Home tab
if (Tab.Id == "ID_TabHome")
{
Tab.Activated += new EventHandler(Tab_Activated);
RibbonPanel ADNPanel = null;
//check if the custom panel exsits
foreach (RibbonPanel panel in Tab.Panels)
{
if (panel.Source.Name == "ID_ADNTestPanel")
{
ADNPanel = panel;
break;
}
}
if (ADNPanel == null)
{
//create custom Panel
ADNPanel = new RibbonPanel();
//create ribbon panel source and bind it to the panel
RibbonPanelSource ADNSource = new RibbonPanelSource();
ADNSource.Id = "ID_ADNTestPanel";
ADNSource.Name = "ADN Test Panel";
ADNPanel.Source = ADNSource;
//create ribbon button
RibbonButton button  = new RibbonButton();
button.IsEnabled = true;
button.IsVisible = true;
button.Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"Images/ListAdd.png", UriKind.RelativeOrAbsolute));
button.LargeImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"Images/open.png", UriKind.RelativeOrAbsolute));
button.ShowImage = true;
button.Size = RibbonItemSize.Standard;
button.ShowText = true;
button.ResizeStyle = RibbonItemResizeStyles.HideText;
button.Id = "ID_ADNTestButton";
button.Name = "ADNTestButtonName";
button.Text = "ADN Test";
button.Orientation = System.Windows.Controls.Orientation.Vertical;
//add the button to the panel
ADNPanel.Source.Items.Add(button);
//delegate the event when ribbon element is activated
ComponentManager.UIElementActivated += new EventHandler(ComponentManager_UIElementActivated);
//add the panel to the tab
Tab.Panels.Add(ADNPanel);
}
}
}
return 0;
}
}
}
#endregion

 

 

image

 

image


Comments

3 responses to “Add Custom Panel and Button to Built-in Tab of Navisworks Ribbon”

  1. I’d like to thank the author for writing such an insightful and informative blog post about custom panel that is not just useful to the readers but also revealing.

  2. frustrated Avatar
    frustrated

    Does any of this work in 2019, I am trying to get a simple Addin to work, and nothing shows in Navisworks Manage 2019, I downloaded the Basic Plugin files, changed it to .net 4.8 and pointed the references to my 2019 navisworks folder.
    Still the addin buttons do not show in Navisworks 2019???!?!?!?!?!?!?!?!

  3. doesn’t work in 2019, still show default name “Tool add-ins 1”, really no solution at all?

Leave a Reply to Technostruct LLCCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading