Tuesday, 10 March 2009

Ribbons in Revit 2010

Revit 2010 due to be released next month sees the introduction of ribbons to the interface, as first popularised in Microsoft Office 2007, then adopted by Autodesk for AutoCAD 2009.

In a recent post I put up a bit of code showing a simple menu and toolbar for Revit 2009, but finally I've overcome some of my installation problems and had chance to have a play with said ribbons in the forthcoming release.

All add-ins appear under the top-level 'Add-in' tab. External tools appear under the push-button menu 'External Tools' in the 'External' panel, and you can add panels to this ribbon like so:



And here's the code to do this:


Public Class RibbonSample
   Implements IExternalApplication

   Public Function OnStartup(ByVal application As Autodesk.Revit.ControlledApplication) As  _
   Autodesk.Revit.IExternalApplication.Result Implements Autodesk.Revit.IExternalApplication.OnStartup

       Try
           'push button
           Dim ribbonPanelButtons As RibbonPanel = application.CreateRibbonPanel("Panel name")
           Dim pushButtonOpenWD As PushButton = ribbonPanelButtons.AddPushButton("Tooltip Bold Title", "Button Name", "C:\pathToMy\coolfunction.dll", "className")
            pushButtonOpenWD.ToolTip = "Tooltip description"

           Return IExternalApplication.Result.Succeeded
       Catch ex As Exception
           MessageBox.Show("Ribbons Failed")
           Return IExternalApplication.Result.Failed
       End Try
   End Function


  Public Function OnShutdown(ByVal application As Autodesk.Revit.ControlledApplication) As  _
  Autodesk.Revit.IExternalApplication.Result Implements Autodesk.Revit.IExternalApplication.OnShutdown

       Return Autodesk.Revit.IExternalApplication.Result.Succeeded

   End Function


End Class

When (or if!) I find the time I'll have a go at adding bitmap images and drop-down menus to my buttons.

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!