Revit 2011 Custom Ribbon Tab

by Guy Robinson 9. April 2010 00:14

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:

 IntellisenseTab

And when creating a panel there are 2 additional overloads:

IntellisensePanel

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 ;-)

Comments are closed

About the Author

A .NET software Developer providing custom applications and commands for architecture firms exclusively working with Autodesk Revit and integration with any associated applications. All from a little place north of Whitianga, New Zealand.

Page List

Disclaimer

I'm self employed so the opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway☺

© Copyright2008

Creative Commons License
Blog content is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

With the following exception. All code snippets, application and libraries are licensed under a a Apache License Version 2.0

Autodesk Revit®

Autodesk: Revit is a product that is wholly owned by Autodesk. Any reference to Revit,Revit API, Revit Architecture, Revit MEP or Revit Structure on this site is made acknowledging this ownership. Refer to Autodesk's own web site and product pages for specific trademark and copyright information. Autodesk represents a great many products and every attempt will be made to respect their ownership whenever one of these other products is mentioned on this site.