In this article, we will talk about the RadioButtonGroup and ToggleButton of the Revit Ribbon API.
A radio button generally is a type of graphical user interface element that allows users to choose only one of a group of options. A toggle button usually is attached to an On/Off or Yes/No field and if placed into a group each can have either On or Off status respectively, turning off one toggle button does not necessarily turn on or off another.
But here in the Revit Ribbon API, they mean the same thing and the RadioButtonGroup and ToggleButton cannot be separated from each other! Each RadioButtonGroup consists of and only consists of a few ToggleButton instances. Even the separator is not allowed in the RadioButtonGroup.
Though looking quite different from the ComboBox and ComboBoxMember, the RadioButtonGroup and ToggleButton can be created much the same way. Of course, there are some small differences in implementation, one of which is radio button (ToggleButton) supports large image besides small image, another of which is it can be set to trigger an external command or not.
Here is some code to create a couple of radio button groups including a separator between them:
private void AddRadioButtonGroups(RibbonPanel panel)
{
string assemFullName = Assembly.GetExecutingAssembly().Location;
string assemPath = Path.GetDirectoryName(assemFullName);
RadioButtonGroupData rbgData1 = new RadioButtonGroupData("RadioButtonGroup1");
RadioButtonGroup rbGroup1 = panel.AddItem(rbgData1) as RadioButtonGroup;
ToggleButtonData rb1MemData1 = new ToggleButtonData("rbg1Mem1", "Toggle11", assemFullName, "RevitAddinCSProject.ExtCmd1");
ToggleButton rb1Mem1 = rbGroup1.AddItem(rb1MemData1);
rb1Mem1.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
rb1Mem1.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
ToggleButtonData rb1MemData2 = new ToggleButtonData("rbg1Mem2", "Toggle12", assemFullName, "RevitAddinCSProject.ExtCmd2");
ToggleButton rb1Mem2 = rbGroup1.AddItem(rb1MemData2);
rb1Mem2.Image = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
rb1Mem2.LargeImage = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
ToggleButtonData rb1MemData3 = new ToggleButtonData("rbg1Mem3", "Toggle13", assemFullName, "RevitAddinCSProject.ExtCmd3");
ToggleButton rb1Mem3 = rbGroup1.AddItem(rb1MemData3);
rb1Mem3.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
rb1Mem3.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_32x32.bmp");
panel.AddSeparator();
RadioButtonGroupData rbgData2 = new RadioButtonGroupData("RadioButtonGroup2");
RadioButtonGroup rbGroup2 = panel.AddItem(rbgData2) as RadioButtonGroup;
ToggleButtonData rb2MemData1 = new ToggleButtonData("rbg2Mem1", "Toggle21", assemFullName, "RevitAddinCSProject.ExtCmd1");
ToggleButton rb2Mem1 = rbGroup2.AddItem(rb2MemData1);
rb2Mem1.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_16x16.bmp");
rb2Mem1.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item1_32x32.bmp");
ToggleButtonData rb2MemData2 = new ToggleButtonData("rbg2Mem2", "Toggle22", assemFullName, "RevitAddinCSProject.ExtCmd2");
ToggleButton rb2Mem2 = rbGroup2.AddItem(rb2MemData2);
rb2Mem2.Image = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_16x16.bmp"), UriKind.Absolute));
rb2Mem2.LargeImage = new BitmapImage(new Uri(Path.Combine(assemPath, "Standalone_Item1_32x32.bmp"), UriKind.Absolute));
ToggleButtonData rb2MemData3 = new ToggleButtonData("rbg2Mem3", "Toggle23", assemFullName, "RevitAddinCSProject.ExtCmd3");
ToggleButton rb2Mem3 = rbGroup2.AddItem(rb2MemData3);
rb2Mem3.Image = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_16x16.bmp");
rb2Mem3.LargeImage = BmpImageSource("RevitAddinCSProject.Resources.Embedded_Item2_32x32.bmp");
}
Still as before, two different approaches to retrieve images have been demonstrated. The AddSeparator() method will add a vertical line between the two RadioButtonGroup groups.
If the following method is called in the OnStartup implementation of an IExternalApplication:
private RibbonPanel CreateRibbonPanel()
{
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinCSProject");
AddRadioButtonGroups(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