Let’s see how to create SplitButton and its members such as PushButton and Separator using RevitAddinWizard.
After the Ribbon Creator tool of the Revit Addin Coder is clicked, the Ribbon Creator window will appear. Then we can indicate a SplitButton is going to be created in a panel of interest through specifying Begin as the first Item, End as the last Item, and PushButton or Separator items in between.
It is not necessary to specify Text, Tooltip, Image, or Command in Ribbon Creator for SplitButton as it does not really have its own look or trigger a command. However the API classes of SplitButton and its associated SplitButtonData have to meet some internal needs such as the Text is required in the constructor of SplitButtonData. Even if passing an empty string as the argument is not enough, Revit would complaint the Text is empty. We will talk about this in a bit detail later on with some code example presented. Since PushButton items of SplitButton group will always display large images in Revit ribbon panels, please remember to pick up a 32x32 pixels bitmap for each of them so that they look good in the Revit Ribbon.
After the OK button is pressed, the following code will be created:
public void AddRibbonItemsToRibbonPanel(RibbonPanel panel)
{
string assemFullName = Assembly.GetExecutingAssembly().Location;
string assemPath = Path.GetDirectoryName(assemFullName);
SplitButtonData cnt1Panel_grp1Data = new SplitButtonData("cnt1Panel_grp1", Guid.NewGuid().ToString());
SplitButton cnt1Panel_grp1 = panel.AddItem(cnt1Panel_grp1Data) as SplitButton;
PushButtonData cnt1Panel_grp1_item1Data = new PushButtonData("cnt1Panel_grp1_item1", @"PushButton 1", assemFullName, "RevitAddinCSProject.ExtCmd1");
PushButton cnt1Panel_grp1_item1 = cnt1Panel_grp1.AddPushButton(cnt1Panel_grp1_item1Data) as PushButton;
cnt1Panel_grp1_item1.ToolTip = @"PushButton 1 Tooltip";
cnt1Panel_grp1_item1.LargeImage = BmpImageSource(@"RevitAddinCSProject.Resources.BigA.bmp");
cnt1Panel_grp1.AddSeparator();
PushButtonData cnt1Panel_grp1_item3Data = new PushButtonData("cnt1Panel_grp1_item3", @"PushButton 2", assemFullName, "RevitAddinCSProject.ExtCmd2");
PushButton cnt1Panel_grp1_item3 = cnt1Panel_grp1.AddPushButton(cnt1Panel_grp1_item3Data) as PushButton;
cnt1Panel_grp1_item3.ToolTip = @"PushButton 2 Tooltip";
cnt1Panel_grp1_item3.LargeImage = BmpImageSource(@"RevitAddinCSProject.Resources.BigB.bmp");
cnt1Panel_grp1.AddSeparator();
PushButtonData cnt1Panel_grp1_item5Data = new PushButtonData("cnt1Panel_grp1_item5", @"PushButton 3", assemFullName, "RevitAddinCSProject.ExtCmd3");
PushButton cnt1Panel_grp1_item5 = cnt1Panel_grp1.AddPushButton(cnt1Panel_grp1_item5Data) as PushButton;
cnt1Panel_grp1_item5.ToolTip = @"PushButton 3 Tooltip";
cnt1Panel_grp1_item5.LargeImage = BmpImageSource(@"RevitAddinCSProject.Resources.BigC.bmp");
}
public static System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)
{
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedPath);
var decoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0];
}
As can be noticed from the constructor code of the SplitButtonData, a GUID is created as the Text argument. It does not need to be meaningful as the Text will be shown nowhere but has to be something otherwise an exception would be thrown out and the whole ribbon creation aborted.
If some extra code is added to the same External Application:
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
AddRibbonItemsToRibbonPanel(panel);
panel.Name = "ABC_APP3_PNL2";
panel.Title = "Buttons created by the RevitAddinWizard";
something like the following will be added to the Revit Ribbon (depending on what the specified images really look like):
As can be seen, all the images of the PushButton items have been changed to something else other than the default provide by the Ribbon Creator.
All the above is supported by RevitAddinWizard.
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