In this article, let’s focus on two more item groups, pull-down button group (PulldownButton) and split button group (SplitButton).
They are almost the same except for some slightly difference in behaviour. Both of them can hold push buttons (PushButton) and separators, and both of them can have a button and a drop down arrow which will pop up their members if being pressed.
The only difference is the appearance of the group button (PulldownButton or SplitButton) and some action to get it updated regarding the SplitButton. The former can have an image (which is not demonstrated in the sample code) and a descriptive text for the group itself but the latter can only show the image and text of the default button or last selected one. An interesting behaviour is that when the split group button is highlighted, a horizontal separator will appear at the middle of the button image, but the first half will only show the button image and the second half will not only show the drop down arrow but also the text of the default or last-time-selected push button rather than the text of the split group itself. So though we have to give a text for the split group, it does not really have a chance to show up.
Here is some code to create a pull-down button group which consists of three push buttons (PushButton) and a separator:
private void AddPulldownButtonGroup(RibbonPanel panel)
{
PulldownButtonData group1Data = new PulldownButtonData("PulldownGroup1", "Pulldown Group 1");
PulldownButton group1 = panel.AddItem(group1Data) as PulldownButton;
PushButtonData itemData11 = new PushButtonData("itemName11", "Command 11", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item11 = group1.AddPushButton(itemData11) as PushButton;
item11.ToolTip = itemData11.Text; // Can be changed to a more descriptive text.
item11.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
item11.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PushButtonData itemData12 = new PushButtonData("itemName12", "Command 12", AssemblyFullName, "RevitAddinCSProject.ExtCmd2");
PushButton item12 = group1.AddPushButton(itemData12) as PushButton;
item12.ToolTip = itemData12.Text; // Can be changed to a more descriptive text.
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", "Command 13", AssemblyFullName, "RevitAddinCSProject.ExtCmd3");
PushButton item13 = group1.AddPushButton(itemData13) as PushButton;
item13.ToolTip = itemData13.Text; // Can be changed to a more descriptive text.
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));
}
Still as before, two different approaches to retrieve images have been demonstrated. The AddSeparator() method will add a horizontal line to the group to separate buttons created before and after if any. Though the method find its places in many classes such as other two, RibbonPanel and ComboBox, there is not really a Separator thing in the Revit API since all these methods return nothing and there is no control at all over the Separator such as line thickness, color or type. All of them will create either a line, vertical or horizontal, short or tall (long), according to the calling context.
Here is some other code to create a split button group which consists of exactly the same three push buttons (PushButton) and separator:
private void AddSplitButtonGroup(RibbonPanel panel)
{
SplitButtonData group1Data = new SplitButtonData("SplitGroup1", "Split Group 1");
SplitButton group1 = panel.AddItem(group1Data) as SplitButton;
PushButtonData itemData11 = new PushButtonData("itemName11", "Command 11", AssemblyFullName, "RevitAddinCSProject.ExtCmd1");
PushButton item11 = group1.AddPushButton(itemData11) as PushButton;
item11.ToolTip = itemData11.Text; // Can be changed to a more descriptive text.
item11.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
item11.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
PushButtonData itemData12 = new PushButtonData("itemName12", "Command 12", AssemblyFullName, "RevitAddinCSProject.ExtCmd2");
PushButton item12 = group1.AddPushButton(itemData12) as PushButton;
item12.ToolTip = itemData12.Text; // Can be changed to a more descriptive text.
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", "Command 13", AssemblyFullName, "RevitAddinCSProject.ExtCmd3");
PushButton item13 = group1.AddPushButton(itemData13) as PushButton;
item13.ToolTip = itemData13.Text; // Can be changed to a more descriptive text.
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));
group1.CurrentButton = item13;
}
As can be noticed above, the code is the same except for the different group class names. In fact, a little bit more control can be exercised upon the SplitButton by setting the IsSynchronizedWithCurrentItem property. If it is false, the first item in the drop down list will always appear on the group button and there is no chance anymore for other items to be there or trigged by simply clicking the group button.
If the following method is called in the OnStartup implementation of an IExternalApplication:
private RibbonPanel CreateRibbonPanel()
{
AddPulldownButtonGroup(panel);
AddSplitButtonGroup(panel);
return panel;
}
A Revit Ribbon will be created and may look like (depending on what those images really are):
The two button groups have been expanded respectively so as to show their similarities and differences.
The RevitAddinWizard can help us create all these code automatically in a few seconds.
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
Hi. I know this post is kind of old. But I'm trying to add more than three pushbuttons to a splitbutton and its giving me problems. For some reason, (2013) after three buttons are added the rest lose the icon that is assigned. Any ideas? Thanks.
Posted by: Michael Coffey | 08/02/2013 at 01:21 AM
Hi Michael, It sounds like an API bug. You may want to report it to Autodesk.
Posted by: Spiderinnet | 08/02/2013 at 02:25 AM
I figured out what the problem was. Some of the properties of the additional buttons didn't get changed when I copied them. Silly mistake.
Posted by: Michael Coffey | 08/11/2013 at 12:49 PM
Michael, thx for the update. Glad you figured it out.
Posted by: Spiderinnet | 08/12/2013 at 03:58 AM