We talked about the uniqueness requirement for the Name of RibbonPanel objects and the flexibility of the Title in the previous post. In fact, the RibbonItem such as PushButton and ToggleButton has a similar issue. In this article, we will discuss something about it.
If a good naming convention is followed for ribbon item creation:
private RibbonPanel CreateRibbonPanel()
{
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
panel.Enabled = true;
panel.Visible = true;
panel.Name = "ABC_APP3_PNL1";
panel.Title = "RevitAddinWizard";
PulldownButtonData group1Data = new PulldownButtonData("PulldownGroup1", "Pulldown Group 1");
group1Data.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
group1Data.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PulldownButton group1 = panel.AddItem(group1Data) as PulldownButton;
PushButtonData itemData11 = new PushButtonData("itemName11", "Add TextBox", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item11 = group1.AddPushButton(itemData11) as PushButton;
item11.ToolTip = "Add TextBox to ABC_APP1_PNL1";
item11.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
item11.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PushButtonData itemData12 = new PushButtonData("itemName12", "Hide ExtCmd2", AssemblyFullName, "RevitAddinCSProject.ExtCmd2");
PushButton item12 = group1.AddPushButton(itemData12) as PushButton;
item12.ToolTip = "Hide ExtCmd2 in ABC_APP1_PNL1";
item12.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
item12.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_32x32.bmp");
group1.AddSeparator();
PushButtonData itemData13 = new PushButtonData("itemName13", "Disable ExtCmd1", AssemblyFullName, "RevitAddinCSProject.ExtCmd3");
PushButton item13 = group1.AddPushButton(itemData13) as PushButton;
item13.ToolTip = "Disable ExtCmd1 in ABC_APP2_PNL1";
item13.Image = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
item13.LargeImage = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
PushButtonData itemData21 = new PushButtonData("itemName21", "ExtCmd1", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item21 = panel.AddItem(itemData21) as PushButton;
item21.ToolTip = "Push button has the same name, itemName.";
item21.Image = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
item21.LargeImage = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
return panel;
}
The ribbon items will be created successfully:
However, if the name of the second PushButton in the PulldownButton is changed to the same name as the first push button:
private RibbonPanel CreateRibbonPanel()
{
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
panel.Enabled = true;
panel.Visible = true;
panel.Name = "ABC_APP3_PNL1";
panel.Title = "RevitAddinWizard";
PulldownButtonData group1Data = new PulldownButtonData("PulldownGroup1", "Pulldown Group 1");
group1Data.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
group1Data.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PulldownButton group1 = panel.AddItem(group1Data) as PulldownButton;
PushButtonData itemData11 = new PushButtonData("itemName11", "Add TextBox", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item11 = group1.AddPushButton(itemData11) as PushButton;
item11.ToolTip = "Add TextBox to ABC_APP1_PNL1";
item11.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
item11.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PushButtonData itemData12 = new PushButtonData("itemName11", "Hide ExtCmd2", AssemblyFullName, "RevitAddinCSProject.ExtCmd2");
PushButton item12 = group1.AddPushButton(itemData12) as PushButton;
item12.ToolTip = "Hide ExtCmd2 in ABC_APP1_PNL1";
item12.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
item12.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_32x32.bmp");
group1.AddSeparator();
PushButtonData itemData13 = new PushButtonData("itemName13", "Disable ExtCmd1", AssemblyFullName, "RevitAddinCSProject.ExtCmd3");
PushButton item13 = group1.AddPushButton(itemData13) as PushButton;
item13.ToolTip = "Disable ExtCmd1 in ABC_APP2_PNL1";
item13.Image = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
item13.LargeImage = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
PushButtonData itemData21 = new PushButtonData("itemName21", "ExtCmd1", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item21 = panel.AddItem(itemData21) as PushButton;
item21.ToolTip = "Push button has the same name, itemName.";
item21.Image = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
item21.LargeImage = new BitmapImage(new Uri(Path.Combine(AssemblyPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
return panel;
}
When Revit is trying to create the pull down button group, the following error message will show up:
After the message box is dismissed, not only the second PushButton will fail to be created but also all followed ones even including the last standalone PushButton:
So it is also important to apply some naming convention to ribbon item creations. In this way, the error can be avoided, and the existing items can be accessed and identified when necessary because the RibbonPanel does not carry any Addin information, the RibbonPanel.GetItems() method returns all items in a single group, and the grouping information in the ribbon panel is lost.
The RevitAddinWizard follows the good practice as introduced here regarding ribbon item 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