BIM World
A Professional BIM Learning Platform


Revit Plugin Development: How to Add Plugins to Ribbon Panels

Once the plugin is ready, the next step is to load it onto the panel.

Revit provides a set of APIs specifically designed for loading plugins. For detailed API information, please refer to Chapter 10 of the official Revit secondary development tutorial. However, the explanations there are quite general and lack practical examples with complete code. Additionally, there is a challenging aspect involving textboxes that I have not yet resolved. I encourage those who study this area further to contribute and supplement this part.

Now, let’s take a look at the source code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;

namespace MenuTool
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    public class Class1 : IExternalApplication
    {
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            string macString = GetMacAddress.GetMacAddressByDos();
            if (macString == "FC:AA:14:42:B5:79" || macString == "1C:1B:0D:37:58:75" || macString == "48:8A:D2:35:95:53" || macString == "48:8A:D2:35:BF:BB" || macString == "48:8A:D2:35:D2:D2" || macString == "48:8A:D2:35:95:50" || macString == "48:8A:D2:35:47:4C")
            {
                // Add a new panel for converting model lines to steel bars
                RibbonPanel ribbonPanel1 = application.CreateRibbonPanel("Model Line to Steel Bar");

                // Add buttons for steel bar conversions on the panel
                PushButtonData item1 = new PushButtonData(
                    "Batch Building Longitudinal Reinforcement",
                    "Longitudinal Reinforcement",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line to ReinforcementBatch Building Longitudinal Reinforcement.dll",
                    "Batch Building Longitudinal Reinforcement.Class1");

                PushButtonData item2 = new PushButtonData(
                    "Quick Stirrup",
                    "Stirrup",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line to ReinforcementQuick Stirrup.dll",
                    "Quick Stirrup.Class1");

                PushButtonData item3 = new PushButtonData(
                    "Batch Create Any Reinforcement",
                    "Any Reinforcement",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line to ReinforcementBatch Create Any Reinforcement.dll",
                    "Batch Create Any Reinforcement.Class1");

                IList listRibbon1 = ribbonPanel1.AddStackedItems(item1, item2, item3);

                // Add a new panel for converting model line families to steel reinforcement
                RibbonPanel ribbonPanel2 = application.CreateRibbonPanel("Model Line Family to Steel Bar");

                // Add buttons for model line family to reinforcement conversions
                PushButtonData item4 = new PushButtonData(
                    "Model Line Family to Longitudinal Reinforcement",
                    "Longitudinal Reinforcement",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line Family to ReinforcementModel Line Family to Longitudinal Reinforcement.dll",
                    "Model Line Family to Longitudinal Reinforcement.Class1");

                PushButtonData item5 = new PushButtonData(
                    "Model Line Family to Hoop Reinforcement",
                    "Hoop Reinforcement",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line Family to ReinforcementModel Line Family to Hoop Reinforcement.dll",
                    "Model Line Family to Hoop Reinforcement.Class1");

                PushButtonData item6 = new PushButtonData(
                    "Convert Model Line Family to Any Reinforcement",
                    "Any Reinforcement",
                    @"C:ProgramDataAutodeskRevitAddins2015Reinforcement PluginModel Line Family to ReinforcementModel Line Family to Any Reinforcement.dll",
                    "Model Line Family to Any Reinforcement.Class1");

                IList listRibbon2 = ribbonPanel2.AddStackedItems(item4, item5, item6);

                // Convert the menus into buttons
                PushButton pushButton1 = listRibbon1[0] as PushButton;
                PushButton pushButton2 = listRibbon1[1] as PushButton;
                PushButton pushButton3 = listRibbon1[2] as PushButton;
                PushButton pushButton4 = listRibbon2[0] as PushButton;
                PushButton pushButton5 = listRibbon2[1] as PushButton;
                PushButton pushButton6 = listRibbon2[2] as PushButton;

                return Result.Succeeded;
            }
            else
            {
                TaskDialog.Show("Revit", "Your machine is not authorized to use this plugin. Please contact the author: Guangzhou Aron 13202088954");
                return Result.Cancelled;
            }
        }
    }
}

Revit secondary development - how to add plugins to panels

The final result is shown in the image above.

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Revit Plugin Development: How to Add Plugins to Ribbon Panels

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up