We talked about the Title and the Name of the RibbonPanel a bit in the previous post. As demonstrated, we can give different Title and Name to the same ribbon panel, but there is something more important regarding why we need to do that. In fact, we have to do so if situations become a bit more complex like creating multiple RibbonPanel instances in a single Addin. Let’s discuss about it in this article.
Suppose we’d like to add one more ribbon panel to the second Addin that we talked about earlier like this:
private void CreateRibbonPanel()
{
RibbonPanel panel1 = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinCS2");
panel1.Enabled = true;
panel1.Visible = true;
panel1.Name = "ABC_APP2_PNL1";
panel1.Title = "RevitAddinWizard";
PushButtonData pbDataExtCmd11 = new PushButtonData("ExtCmd1", "Command 1", Assembly.GetExecutingAssembly().Location, "RevitAddinCS2.ExtCmd");
PushButton pbExtCmd11 = panel1.AddItem(pbDataExtCmd11) as PushButton;
pbExtCmd11.ToolTip = "External Command 11";
pbExtCmd11.LargeImage = BmpImageSource("RevitAddinCS2.Resources.ExtCmd32x32.bmp");
pbExtCmd11.Image = BmpImageSource("RevitAddinCS2.Resources.ExtCmd16x16.bmp");
RibbonPanel panel2 = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinCS2");
panel2.Enabled = true;
panel2.Visible = true;
panel2.Name = "ABC_APP2_PNL2";
panel2.Title = "RevitAddinWizard";
PushButtonData pbDataExtCmd21 = new PushButtonData("ExtCmd1", "Command 1", Assembly.GetExecutingAssembly().Location, "RevitAddinCS2.ExtCmd");
PushButton pbExtCmd21 = panel2.AddItem(pbDataExtCmd21) as PushButton;
pbExtCmd21.ToolTip = "External Command 1";
pbExtCmd21.LargeImage = BmpImageSource("RevitAddinCS2.Resources.ExtCmd32x32.bmp");
pbExtCmd21.Image = BmpImageSource("RevitAddinCS2.Resources.ExtCmd16x16.bmp");
}
When Revit is trying to load and create the second ribbon panel in the same Addin, some error message like the following will show up:
Clearly as stated in the message, Revit does not allow different ribbon panels to have the same name, and due to this the second RibbonPanel will not be created.
But this raises a few questions:
1. Why Revit complained so as we did feed a unique name to each of the RibbonPanel?
2. Does Revit accept duplicate Title for different ribbon panels?
3. Why does not the CreateRibbonPanel() accept both a Name argument and a Title argument as most of ribbon item data classes do?
I think the answer to the first question is that Revit takes the string argument of the CreateRibbonPanel() as both Title and Name for the RibbonPanel. The error message clearly indicates that the argument is used as the Name of the RibbonPanel, and the display of the ribbon panel proves that Revit uses it as the Title for the RibbonPanel as well. In addition, it’s too late to reset the Name as a different and unique one after the call.
The answer to the second question is apparently YES. If we change the string argument of the CreateRibbonPanel() to something unique and then reset the Title property of all ribbon panels to the same string, “RevitAddinWizard”, for example, there will be no problem at all.
The answer to the third question is unknown.
So, it’s apparently not a good practice to feed the project or assembly name to the CreateRibbonPanel() method. Instead, I would recommend something like:
• Providing a GUID to the CreateRibbonPanel() method;
• Setting the Name as something unique and easy to remember, e.g. following the naming conversion as introduced in the previous article;
• Setting the Title as what makes sense.
private void CreateRibbonPanel()
{
RibbonPanel panel1 = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
panel1.Enabled = true;
panel1.Visible = true;
panel1.Name = "ABC_APP2_PNL1";
panel1.Title = "RevitAddinWizard";
PushButtonData pbDataExtCmd11 = new PushButtonData("ExtCmd1", "Command 1", Assembly.GetExecutingAssembly().Location, "RevitAddinCS2.ExtCmd");
PushButton pbExtCmd11 = panel1.AddItem(pbDataExtCmd11) as PushButton;
pbExtCmd11.ToolTip = "External Command 11";
pbExtCmd11.LargeImage = BmpImageSource("RevitAddinCS2.Resources.ExtCmd32x32.bmp");
pbExtCmd11.Image = BmpImageSource("RevitAddinCS2.Resources.ExtCmd16x16.bmp");
RibbonPanel panel2 = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
panel2.Enabled = true;
panel2.Visible = true;
panel2.Name = "ABC_APP2_PNL2";
panel2.Title = "RevitAddinWizard";
PushButtonData pbDataExtCmd21 = new PushButtonData("ExtCmd1", "Command 1", Assembly.GetExecutingAssembly().Location, "RevitAddinCS2.ExtCmd");
PushButton pbExtCmd21 = panel2.AddItem(pbDataExtCmd21) as PushButton;
pbExtCmd21.ToolTip = "External Command 1";
pbExtCmd21.LargeImage = BmpImageSource("RevitAddinCS2.Resources.ExtCmd32x32.bmp");
pbExtCmd21.Image = BmpImageSource("RevitAddinCS2.Resources.ExtCmd16x16.bmp");
}
With similar changes to all the panel creation code in the three Addins, all the four panels will look like the following this time:
As can be seen, now all the panels have the same name, RevitAddinWizard, but the three buttons in the PulldownButton group of panel of the third Addin can still find them and do something to their items:
The RevitAddinWizard will follow the good practice as introduced here regarding ribbon panel creation.
Links to some related articles:
Ribbon of Revit API - PushButton And TextBox
Use Ribbon Creator of RevitAddCoder to Create PushButton And Separator
Use Ribbon Creator of RevitAddCoder to Create TextBox
Ribbon of Revit API - ComboBox And ComboBoxMember
Use Ribbon Creator of RevitAddCoder to Create ComboBox And ComboBoxMember
Ribbon of Revit API - PulldownButton And SplitButton
Use Ribbon Creator of RevitAddCoder to Create PulldownButton And PushButton
Use Ribbon Creator of RevitAddCoder to Create SplitButton And PushButton
Ribbon of Revit API - RadioButtonGroup And ToggleButton
Use Ribbon Creator of RevitAddCoder to Create RadioButtonGroup And ToggleButton
Ribbon of Revit API - Stacked Group And AddStackedItems
Ribbon of Revit API - Stacked Group And PulldownButton
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And PushButton Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And TextBox Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And PulldownButton Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And ComboBox Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And Various Items
Ribbon of Revit API - Slideout
Use Ribbon Creator of RevitAddCoder to Create Slideout And Various Buttons
Ribbon of Revit API - Manipulate Panels Created by Other Addins
Access Ribbons Created by Ribbon Creator From Another Addin
Update Ribbons Created by Ribbon Creator From Another Addin
Use Ribbon Creator of RevitAddCoder to Create a Comprehensive Ribbon Panel
Ribbon of Revit API - Title And Name of Panels
Ribbon of Revit API - Text And Name of RibbonItem
Ribbon of Revit API - LongDescription And TooltipImage of RibbonItem
Recent Comments