Revit API 2012 makes some changes to the existing libraries and provides something new as always. Let us look at some critical changes in the Revit API 2012.
In this post, we will focus on the new API method CreateRibbonTab() which can create some custom ribbon tabs. It accepts a ribbon tab name and returns nothing. It is very straightforward to use. Here is an example:
private RibbonPanel CreateRibbonPanel()
{
cachedUiCtrApp.CreateRibbonTab("RevitAddinWizard");
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinWizard", Guid.NewGuid().ToString());
//panel.Name = Guid.NewGuid().ToString(); //Set to a friendly and unique name and uncomment the code if necessary.
panel.Title = "RevitAddinCS1";
////Default button:
PushButtonData pbDataExtCmd = new PushButtonData("ExtCmd", "ExtCmd", Assembly.GetExecutingAssembly().Location, "RevitAddinCS1.ExtCmd");
PushButton pbExtCmd = panel.AddItem(pbDataExtCmd) as PushButton;
pbExtCmd.ToolTip = "ExtCmd";
pbExtCmd.LargeImage = BmpImageSource("RevitAddinCS1.Resources.ExtCmd32x32.bmp");
pbExtCmd.Image = BmpImageSource("RevitAddinCS1.Resources.ExtCmd16x16.bmp");
////More buttons:
return panel;
}
Since our own ribbon tab has been created by the CreateRibbonTab() call, we’d like to add our ribbon panel into the ribbon tab this time through using another signature of the CreateRibbonPanel() method which has been there since version 2011. Though the signature accepts a ribbon tab name argument, it is not really useful for Revit 2011 addins since the only candidate is the Addins ribbon tab and there is no way to create a new one. Thus using the signature without the ribbon tab argument seems just better in that era.
Now in the Revit API 2012, it is possible to create a custom ribbon tab first and add a custom ribbon panel to it next:
Revit Addin Wizard (RevitAddinWizard) provides the ribbon tab creation option when Revit 2012 is targeted at in the wizard page.
By the way, the ribbon panel creation code in the main external application will also follow the good practice now, assigning a GUID to the panel name argument of the CreateRibbonPanel() method and resetting its name and title afterwards. In this way, Revit can still create the ribbon panel successfully even if it has a duplicate title as any other.
Recent Comments