Commands
Step 1. Create the command
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;
namespace RevitAPIRibbonCommand
{
[Transaction(TransactionMode.Manual)]
public class MyCommand : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// Your command logic here
TaskDialog.Show("Hello Revit", "Your custom command executed!");
return Result.Succeeded;
}
}
}Step 2. Create the Ribbon Panel
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace RevitAPIRibbonCommand
{
public class RibbonSetup : IExternalApplication
{
public Result OnStartup(UIControlledApplication application)
{
// Create a ribbon panel
RibbonPanel ribbonPanel = application.CreateRibbonPanel("Custom Tools");
// Create a push button
PushButtonData buttonData = new PushButtonData(
"MyCommand", "Execute Command",
System.Reflection.Assembly.GetExecutingAssembly().Location,
"RevitAPIRibbonCommand.MyCommand");
PushButton button = ribbonPanel.AddItem(buttonData) as PushButton;
// Add a tooltip
button.ToolTip = "Click to execute your custom command.";
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}
}