Revit Ribbon API supports combo boxes (ComboBox) which can hold some similar and exclusive options for users to pick one from. Each ComboBox can have multiple ComboBoxMember items each of which can have both a small image and a text.
ComboBox and ComboBoxMember are all data centric and they are not supposed to trigger any commands, so they do not care about the assembly location or command classes.
Though the ComboBox can be held by the RibbonPanel directly, it does not really share the same height as the container. Instead, it is about one third tall as the panel, just like the TextBox we introduced previously, and only small images are supported in the ComboBox because of the same reason. And it has a constant width, this time not like the TextBox which default width can be adjusted by the Width property.
Here is some code to create a couple of ComboBox groups each of which holds a few members (ComboBoxMember):
private void AddRibbonComboBox(RibbonPanel panel)
{
string assemFullName = Assembly.GetExecutingAssembly().Location;
string assemPath = Path.GetDirectoryName(assemFullName);
ComboBoxData cbData1 = new ComboBoxData("Combo1");
Autodesk.Revit.UI.ComboBox combo1 = panel.AddItem(cbData1) as Autodesk.Revit.UI.ComboBox;
ComboBoxMemberData cb1MemData1 = new ComboBoxMemberData("com1Mem1", "Combo1 item 1");
ComboBoxMember cb1Mem1 = combo1.AddItem(cb1MemData1);
cb1Mem1.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
ComboBoxMemberData cb1MemData2 = new ComboBoxMemberData("com1Mem2", "Combo1 item 2");
ComboBoxMember cb1Mem2 = combo1.AddItem(cb1MemData2);
cb1Mem2.Image = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
ComboBoxMemberData cb1MemData3 = new ComboBoxMemberData("com1Mem3", "Combo1 item 3");
ComboBoxMember cb1Mem3 = combo1.AddItem(cb1MemData3);
cb1Mem3.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
ComboBoxData cbData2 = new ComboBoxData("Combo2");
Autodesk.Revit.UI.ComboBox combo2 = panel.AddItem(cbData2) as Autodesk.Revit.UI.ComboBox;
ComboBoxMemberData cb2MemData1 = new ComboBoxMemberData("com2Mem1", "Combo2 item 1");
ComboBoxMember cb2Mem1 = combo2.AddItem(cb2MemData1);
cb2Mem1.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
ComboBoxMemberData cb2MemData2 = new ComboBoxMemberData("com2Mem2", "Combo2 item 2");
ComboBoxMember cb2Mem2 = combo2.AddItem(cb2MemData2);
cb2Mem2.Image = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
ComboBoxMemberData cb2MemData3 = new ComboBoxMemberData("com2Mem3", "Combo2 item 3");
ComboBoxMember cb2Mem3 = combo2.AddItem(cb2MemData3);
cb2Mem3.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
}
private System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)
{
Stream stream = this.GetType().Assembly.GetManifestResourceStream(embeddedPath);
var decoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0];
}
As can be noticed, two different image handling approaches are also introduced, one of which is to use some embedded resources and the other of which is to use some stand alone images which reside in the same folder as the running assembly is. Please make sure the images are embedded as specified and in the right place so as for the code to function properly.
Another matter worth of a minute to talk about is the namespace of the ComboBox. As coded above, the full type name Autodesk.Revit.UI.ComboBox had to be used, otherwise, some ambiguity compiler errors would occur because this ComboBox has the same name as the Windows Form ComboBox, just like the TextBox we talked about last time. For ComboBoxData, ComboBoxMember, and ComboBoxMemberData, things are fine as Windows Form do not have such things.
If the following method is called in the OnStartup implementation of an IExternalApplication:
private RibbonPanel CreateRibbonPanel()
{
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinCSProject");
AddRibbonComboBox(panel);
return panel;
}
A Revit Ribbon will be created and may look like (depending on what those images really are):
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
Recent Comments