Revit APP Blog

Information on Revit APP.

Browsing Posts published on 2010/06/25

Revit 2011 API provides user ways to create their own ribbon panel & buttons. Plus the shortcut capability, it makes addins similar as built-in functionalities. To add your own ribbon stuff, you only need to implement the IExternalApplication interface, and in the OnStartup function, write code like this:

public Result OnStartup(UIControlledApplication uiControlledApplication)
{
   // The location of this command assembly
   string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

   // begin to create custom Ribbon panel and command buttons.
   // create a Ribbon panel.
   RibbonPanel myPanel = uiControlledApplication.CreateRibbonPanel(“MyRibbonPanel”);

   // the button in the new panel
   PushButton pushButton = myPanel.AddItem(new PushButtonData(“MyPushButton”, “Command1″, assemblyPath, typeof(Command1).FullName)) as PushButton;
   pushButton.ToolTip = “Command1″;
   // the large image uses for tooltip
   Command1.LargeImage = new BitmapImage(new Uri(Path.Combine(buttonImageDir, “Command1_Large.bmp”)));
   // image uses for the button
   Command1.Image = new BitmapImage(new Uri(Path.Combine(buttonImageDir, “Command1_Small.bmp”)));

   RadioButtonGroupData radioButtonGroupData = new RadioButtonGroupData(“TypeSelector”);
   RadioButtonGroup radioButtonGroup = (RadioButtonGroup)(myPanel.AddItem(radioButtonGroupData));
   ToggleButton toggleButton = radioButtonGroup.AddItem(new ToggleButtonData(“Type1″, “Type1″, assemblyPath, “MyApp.Type1″));
   toggleButton.LargeImage = new BitmapImage(…large image uri);
   toggleButton.Image = new BitmapImage(…image uri);
   toggleButton = radioButtonGroup.AddItem(new ToggleButtonData(“Type2″, “Type2″, assemblyPath, “MyApp.Type1″));
   toggleButton.LargeImage = new BitmapImage(…large image uri);
   toggleButton.Image = new BitmapImage(…image uri);

   return Result.Succeeded;
}

Go to the SDK\Samples\Ribbon\CS folder to get more detail examples.

If you want to use images added in the solution (so you don’t need external image file when deployment), you can add all needed image files in projects and set their “Build Action” in property as “Embedded Resource”, and get the ImageSource using following code:

System.IO.Stream file = app.GetManifestResourceStream(namespace + “.” + imageName);
PngBitmapDecoder bd = new PngBitmapDecoder(file, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

 Please replace the namespace with your own namespace name.

Revit 2011 supports user defined keyboard shortcut for both build-in commands and API addin commands. Here we show you the way to set your own keyboard shortcut for your addin commands. Before the setting, please make sure “Add-ins” tab shows up in your Revit ribbon and your addin commands shows up under the “Add-ins” tab.

Go to “View” tab, click the “User Interface” dropdown menu, and select the “Keyboard Shortcuts” item like following pic.

Then in the pop up dialog, select “Add-ins tab” in the Filter dropdown combobox, like following pic:

After the selection, you can see all your commands under Add-ins tab, choose the command item and input the keyboard shortcuts in the “Press new keys” area, then click “Assign” button:

Click “OK” to close the Keyboard Shortcuts dialog. Then you can use your new defined shortcuts for your own commands now.

Powered by WordPress Web Design by SRS Solutions © 2012 Revit APP Blog Design by SRS Solutions