Navisworks API for stacked ribbon buttons

Navisworks API for stacked ribbon buttons

serg-001
Participant Participant
1,531 Views
4 Replies
Message 1 of 5

Navisworks API for stacked ribbon buttons

serg-001
Participant
Participant

Hello,

 

How to created stacked vertically Ribbon buttons via Navisworks API? I want to have two or three ribbon buttons located in one column one below other.

 

I have found this for Revit API, called "stacked ribbon items" on page "Ribbon Panels and Controls". Example on the picture, there are two buttons: "My Button #1" and  "My Button #2" below it.

How to get similar buttons in Navisworks plugin?

 

Thank you

0 Likes
1,532 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @serg-001 ,

Could you please try using the below sample code?

I tested in Navisworks Manage 2023.

 public class Class1 : AddInPlugin
    {
        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")
                {
                    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(@"....\red.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";
                        

                        RibbonButton button2 = new RibbonButton();
                        button2.IsEnabled = true;
                        button2.IsVisible = true;
                        button2.Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"....\red.png", UriKind.RelativeOrAbsolute));
                        button2.ShowImage = true;
                        button2.Size = RibbonItemSize.Standard;
                        button2.ShowText = true;
                        button2.ResizeStyle = RibbonItemResizeStyles.HideText;
                        button2.Id = "ID_ADNTestButton2";
                        button2.Name = "ADNTestButtonName2";
                        button2.Text = "ADN Test2";

                        RibbonButton button3 = new RibbonButton();
                        button3.IsEnabled = true;
                        button3.IsVisible = true;
                        button3.Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"....\red.png", UriKind.RelativeOrAbsolute));
                        button3.ShowImage = true;
                        button3.Size = RibbonItemSize.Standard;
                        button3.ShowText = true;
                        button3.ResizeStyle = RibbonItemResizeStyles.HideText;
                        button3.Id = "ID_ADNTestButton3";
                        button3.Name = "ADNTestButtonName3";
                        button3.Text = "ADN Test3";

                       
                        //add the button to the panel
                        ADNPanel.Source.Items.Add(button);
                        ADNPanel.Source.Items.Add(new RibbonRowBreak());
                        ADNPanel.Source.Items.Add(button2);
                        ADNPanel.Source.Items.Add(new RibbonRowBreak());
                        ADNPanel.Source.Items.Add(button3);
                        ADNPanel.Source.Items.Add(new RibbonRowBreak());
                        
                        //delegate the event when ribbon element is activated
                        ComponentManager.UIElementActivated += new EventHandler<UIElementActivatedEventArgs>(ComponentManager_UIElementActivated);
                        //add the panel to the tab
                        Tab.Panels.Add(ADNPanel);
                       
                    }

                }
            }
            return 0;
        }
        
        void ComponentManager_UIElementActivated(object sender, UIElementActivatedEventArgs e)
        {
            if(e != null && e.Item != null && e.Item.Id != null&& e.Item.Id == "ID_ADNTestButton")
            {
                MessageBox.Show("Button 1 is clicked!");
            }
            if (e != null && e.Item != null && e.Item.Id != null && e.Item.Id == "ID_ADNTestButton2")
            {
                System.Windows.Forms.MessageBox.Show("Button 2 is clicked!");
            }
            if (e != null && e.Item != null && e.Item.Id != null && e.Item.Id == "ID_ADNTestButton3")
            {
                System.Windows.Forms.MessageBox.Show("Button 3 is clicked!");
            }
        }
    }

Here is the Result I got

Buttons.png


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 5

serg-001
Participant
Participant

Hi @naveen.kumar.t ,

 

I tried to get similar behavior within xaml-file.

I was not able to get it work with RibbonPanel, probably because I have extra ribbon buttons on the panel, which should be arranged as usual ribbon buttons. I replaced RibbonPanel with RibbonRowPanel. And RibbonRowPanel and RibbonRowBreak work fine together.

 

Thanks!

 

 

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @serg-001 ,

 

That's great news.
Did you use XAML to create the ribbon buttons?
If possible, Could you please explain how did you resolve this issue with a simple sample code?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

serg-001
Participant
Participant

This is something like this:

 

		...
        <RibbonPanel ...>
            <RibbonPanelSource ...>
                <RibbonRowPanel>
                    <roamer:NWRibbonButton ... />
                    <RibbonRowBreak />
                    <roamer:NWRibbonButton ... />
                    <RibbonRowBreak />
                    <roamer:NWRibbonButton ... />
                </RibbonRowPanel>
            </RibbonPanelSource>
        </RibbonPanel>
		...

 

 

 

I was looking for some kind of the official documentation on the subject, but didn't find something.