At the beginning of the year I showed you how to add your own tab to the Revit Ribbon. I’ve updated this now for Revit 2011. However, I’ve taken the chainsaw to my code for 2 reasons. The API wasn’t very elegant and the 2011 ribbon seems to behave itself a lot more than the ribbon in Revit 2010. So there is no need to manage context switching as in Revit 2010. Having said this, if anyone finds this new code isn’t behaving please let me know ;-)
The code is now implemented as an extension method to the UIControlledApplication . This means as long as you reference the extension method namespace correctly you should see this in intellisense when creating a custom tab:
And when creating a panel there are 2 additional overloads:
Although the extension method is contained in the example assembly I’ve designed the extension method to sit in an external common assembly that all your commands use. As long as all your applications use this common assembly you will be able to add panels to a common ribbon tab by name.
So in summary to add a custom tab use the following :
public Result OnStartup(UIControlledApplication application)
{
try
{
var tab = application.CreateRibbonTab("MyTab");
And to add a panel to the custom tab there are 2 overloads. The first where you pass the tab instance:
var tab = application.CreateRibbonTab("MyTab");
var panel = application.CreateRibbonPanel(tab, "Test Panel");
And the second where you name the tab
var panel = application.CreateRibbonPanel("MyTab", "Test Panel");
rather than creating it explicitly. If the tab with the specified name doesn’t exist the extension method will create it. Code in the usual place along with a binary and addin. Note you’ll need to modify the path in the addin .Enjoy!!
Journal Comments
The example application contains a few other examples of nice new API’s for Revit 2011. The minor one is the ability to easily add a comment to the journal. This is a method to the Revit Application instance so you can add comments from either external applications or external commands:
Application.WriteJournalComment("It's verified you do agree",true);
If you don’t want to write the time your comment was added to the journal use false instead.
Task Dialog Boxes
The other new API in this example application are Task Dialog boxes. These dialogs will be useful in many situations where you want to alert users to an event , a simple window for getting user feedback, help windows etc. The example pretty much covers all options. A nice feature is the addition of up to 4 linked command buttons providing an easy way to get more than the usual yes/no response to a dialog. In the example application I’ve added 2 commands:
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,"A jump …");
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "A jump …");
Then a switch to action the user response. Clicking on a link closes the dialog:
switch (result)
{
case TaskDialogResult.Close:
app.WriteJournalComment("closed dialog", false); // writes a
break;
case TaskDialogResult.CommandLink1:
Process.Start("http://www.lukehurley.co.nz/biomusic/
break;
case TaskDialogResult.CommandLink2:
Process.Start("http://www.lukehurley.co.nz/2008/07/06/
break;
}
The other new API I use in the example is the interface IExternalCommandAvailiability to disable the command in the family editor (just wanted to check tab behaviour in the family context). Jeremy covers this API in depth so I won’t bother ;-)