晴空微澜 发表于 2023-1-21 16:10:53

[Revit二次开发] Ribbon菜单的创建

https://blog.csdn.net/qq_40416052/article/details/85010831
(1)项目完整代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

using System.Windows.Media.Imaging;//需要添加引用:PresentationCore、System.Xaml、WindowsBase
using Autodesk.Revit.UI.Events;

namespace Ribbon
{
   
   
    public class Class1 : IExternalApplication
    {
      public Result OnShutdown(UIControlledApplication application)
      {
            return Result.Succeeded;
      }

      public Result OnStartup(UIControlledApplication application)
      {
            application.CreateRibbonTab("我的工具");//创建选型卡页名称
            RibbonPanel panel1 = application.CreateRibbonPanel("我的工具", "欢迎页");//创建选项卡面板
            PushButtonData pdb = new PushButtonData("我的工具", "欢迎使用", @"E:\27.Revit development\HelloWorld\HelloWorld\bin\Debug\HelloRevit.dll", "HelloRevit.Class1");//此处为我编写的HelloWorld程序,,相关链接在文章最后
            PushButton pb = panel1.AddItem(pdb) as PushButton;

            RibbonPanel panel2 = application.CreateRibbonPanel("我的工具", "工具");//创建面板
            SplitButtonData splitData = new SplitButtonData("我的集合", "创建工具");//创建记忆下拉按钮
            SplitButton sb = panel2.AddItem(splitData) as SplitButton;

            PushButtonData spd = new PushButtonData("我的工具", "创建", @"E:\27.Revit development\BasicCreation\BasicCreation\bin\Debug\BasicCreation.dll", "BasicCreation.Class1");//此处的插件是:创建墙体并实现墙体的复制、移动和镜像,相关链接在文章最后
            //为按钮添加图片
            spd.LargeImage = new BitmapImage(new Uri(@"E:\27.Revit development\Bitmap.png"));//添加位图的地址
            sb.AddPushButton(spd);//完成添加

            //添加分隔符
            panel2.AddSeparator();
            PulldownButtonData pdbd = new PulldownButtonData("我的工具", "检查");
            PushButtonData pushbtn = new PushButtonData("我的工具", "碰撞检查", @"E:\27.Revit development\Collision\Collision\bin\Debug\Collision.dll", "Collision.Class1");//这是我写的一个碰撞检查插件,相关链接在文章最后
            PulldownButton btn = panel2.AddItem(pdbd) as PulldownButton;
            btn.LongDescription = "检查当前物体是否碰撞";
            btn.AddPushButton(pushbtn);

            //创建下拉组合框
            RibbonPanel panel3 = application.CreateRibbonPanel("我的工具", "文件");
            ComboBoxData cbd = new ComboBoxData("选项");
            ComboBox cBox = panel3.AddItem(cbd) as ComboBox;

            if(cBox != null)
            {
                cBox.ItemText = "选择操作";
                cBox.ToolTip = "请选择想要进行的操作";
                cBox.LongDescription = "选择一直接关闭,选择二关闭并修改";

                ComboBoxMemberData cbmd = new ComboBoxMemberData("A", "关闭");
                ComboBoxMemberData cbmd2 = new ComboBoxMemberData("B", "关闭并修改");

                cbmd.GroupName = "编辑操作";
                cBox.AddItem(cbmd);
                cBox.AddItem(cbmd2);
            }
            cBox.CurrentChanged += change;
            cBox.DropDownClosed += closed;


            return Result.Succeeded;
      }

      private void closed(object sender, ComboBoxDropDownClosedEventArgs e)
      {
            TaskDialog.Show("关闭", "已关闭");
      }

      private void change(object sender, ComboBoxCurrentChangedEventArgs e)
      {
            TaskDialog.Show("修改", "已修改");
      }
    }
}Ribbon菜单插件介绍:
(2)项目代码中用到的插件:

创建墙体并实现墙体的复制、移动和镜像

使用ElementIntersectFilter进行冲突检查

(3)面板中制作位图需要添加的引用:PresentationCore、System.Xaml、WindowsBase


(4)代码编写完成后,将Revit2018.exe的路径设置外“启动外部程序”





(5)在Revit2018中加载应用程序 :将Addins\2014下的Ribbon.addin 文件复制到Addins\2018文件夹下: 加载应用程序: 效果: 参考文献:周婧祎《Autodesk Revit 2016二次开发入门教程》
页: [1]
查看完整版本: [Revit二次开发] Ribbon菜单的创建