Let’s see how to create PulldownButton 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 PulldownButton 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 Command for the PulldownButton as it does not trigger a command but necessary to specify Text, Tooltip, and Image as the PulldownButton still has a look. Since PulldownButton and PushButton items will always display large images in Revit ribbon panels, please remember to pick up a 32x32 pixels bitmap for each of them so that their look in the Revit Ribbon can be good.
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);
PulldownButtonData cnt1Panel_grp1Data = new PulldownButtonData("cnt1Panel_grp1", @"PulldownButton Group");
PulldownButton cnt1Panel_grp1 = panel.AddItem(cnt1Panel_grp1Data) as PulldownButton;
cnt1Panel_grp1.ToolTip = @"PulldownButton Group Tooltip";
cnt1Panel_grp1.LargeImage = BmpImageSource(@"RevitAddinCSProject.Resources.ExtCmd.bmp");
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];
}
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 image provide by the Ribbon Creator but the PulldownButton use the default one.
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
So I have been trying to get a new panel added onto a ribbon using the ribbon creator, and I think I may have found an "error" with the code added to the External Application.
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
-should be-
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("Tab Name", Guid.NewGuid().ToString());
I am a noob to C# so correct me if I am wrong or if I missing something else. But for me, adding this was the only way to get the new panel to load into the ribbon.
Windows 7 64bit
Revit Build:20110916_2132(x64) Update Release 2
Visual Studio 2010 Professional - Student Edition
Newest RevitaddinWizard
thanks for the cool wizard too.
Mark
Posted by: Mark Peterson | 01/05/2012 at 09:21 PM
You are welcome.
It must be something new in the Revit API 2011 Update 2 which supports creating new Ribbon Tabs in the second method signature. However, if the first signature could not successfully add a Ribbon Panel into the Addin tab, there must be something wrong with the API itself rather than the RevitAddinWizard. I can help diagnose the issue further if more information is provided.
Thanks for using the RevitAddinWizard and the feedback.
Posted by: Spiderinnet | 01/06/2012 at 04:06 AM
Instead of me trying to explain it I just made a video. http://www.youtube.com/watch?v=jKU97XFJd08
In short, I used the revit add in template and then I am trying to add another panel into the new ribbon tab. I might just be assuming that it is more plug n play then it actually is. Again I am new to C#, so i'm sure I am just doing something obvious wrong. Anyways take a look at let me know what you think.
thanks a lot for the help.
Posted by: Mark Peterson | 01/06/2012 at 08:45 PM
Tried to have a look but found the video is private.
I kinda figured what's going on. You created a Ribbon Tab and added a Panel to it using RevitAddinWizard first. Next you created a new Ribbon Panel using the Ribbon Creator Coder and would like to append the Panel to the same Tab as well but found another signature needed to be used.
You were right then. Ribbon Creator Coder would only add the newly created Ribbon Panel to the Addin Tab by default instead of the Tab you liked. Another CreateRibbonPanel() signature had to be used to get the latter done as you experienced.
Thanks for the valuable feedback. It may indicate that the Ribbon Creator needs some revisit as well, like adding a Ribbon Tab list to choose from .
Posted by: Spiderinnet | 01/07/2012 at 07:20 PM
Sorry i meant to hit unlisted instead of private. You should be able to see it now.
Posted by: Mark Peterson | 01/07/2012 at 09:35 PM
NP. Now I saw the nice video and got what happened.
You were using Revit 2012 and chose the version 2012 accordingly in the RevitAddinWizard and the Ribbon Tab and Panel was created successfully. You could successfully create the Ribbon Creator method too. But when you tried to create a new Ribbon Panel using the test code as demonstrated in the post to host the Ribbon items, you found it nowhere. In fact, the Panel was already there in the "AddIn" Ribbon Tab which was on the left to your own Ribbon Tab, with two more others in between.
Once again, if the first signature of the CreateRibbonPanel() is used, all Ribbon Panels will be added to the 'AddIn' tab; the second allows you to name a custom/new Ribbon Tab. In Revit API 2011, though the second signature is already there we cannot create any new Ribbon Tabs and all third party Ribbon Panels have to go into the 'AddIn' one and naming any other existing Revit native Ribbon Tabs would just fail. That explained why RevitAddinWizard and its Wizards, Coders and Widgets only used the first signature before. BTW, if no version is particularly mentioned, code and concepts apply to Revit API 2011.
In terms of the matter about Ribbon Panel Title and Name, I have another article to address it:
Ribbon of Revit API – 8: Title and Name of RibbonPanel
For your convenience, here is the link:
http://spiderinnet.typepad.com/blog/2011/03/ribbon-panel-ribbonpanel-and-items-ribbonitem-of-revit-api-part-8-title-and-name-of-ribbon-panel-ribbonpanel.html
Posted by: Spiderinnet | 01/07/2012 at 11:07 PM