Revit 二次开发 交互及UIAPI之Ribbon菜单

Posted chenyanbin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Revit 二次开发 交互及UIAPI之Ribbon菜单相关的知识,希望对你有一定的参考价值。

学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=14

Ribbon菜单

技术图片

 

技术图片

 

技术图片

 

创建控件(按钮等)

技术图片

 

Ribbon菜单实例练习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using System.Windows.Media.Imaging;

namespace RevitDevTV
{
    /// <summary>
    /// Ribbon练习
    /// </summary>
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Ribbon : IExternalApplication
    {
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            application.CreateRibbonTab("我的工具");
            RibbonPanel panel1 = application.CreateRibbonPanel("我的工具", "欢迎页");
            PushButtonData pbd = new PushButtonData("我的工具", "欢迎使用",@"C:UsersappleDesktopRevitDevTVRevitDevTVinDebugRevitDevTV.dll", "RevitDevTV.ShowHello");
            PushButton pb = panel1.AddItem(pbd) as PushButton;

            RibbonPanel panel2 = application.CreateRibbonPanel("我的工具","工具");
            SplitButtonData splitData = new SplitButtonData("我的集合", "创建工具");
            SplitButton sb = panel2.AddItem(pbd) as SplitButton;

            PushButtonData spd = new PushButtonData("我的工具", "创建", @"C:UsersappleDesktopRevitDevTVRevitDevTVinDebugRevitDevTV.dll", "RevitDevTV.ShowHello");
            spd.LargeImage = new BitmapImage(new Uri(@"C:UsersappleDesktop1.png"));
            panel2.AddItem(spd);

            panel2.AddSeparator(); //添加分割线

            PulldownButtonData pdbd = new PulldownButtonData("我的工具", "检查");
            PushButtonData pushbtn = new PushButtonData("我的工具", "碰撞检查", @"C:UsersappleDesktopRevitDevTVRevitDevTVinDebugRevitDevTV.dll", "RevitDevTV.ShowHello");
            PulldownButton btn = panel2.AddItem(pdbd) as PulldownButton;
            btn.LongDescription = "检查当前物体是否碰撞"; //添加下拉按钮的完整描述
            btn.AddPushButton(pushbtn); //添加命令按钮到下拉按钮

            RibbonPanel panel3 = application.CreateRibbonPanel("我的工具", "文件");
            ComboBoxData cbd = new ComboBoxData("选项");
            Autodesk.Revit.UI.ComboBox cBox = panel3.AddItem(cbd) as Autodesk.Revit.UI.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("修改", "已修改");
        }
    }
}

 

以上是关于Revit 二次开发 交互及UIAPI之Ribbon菜单的主要内容,如果未能解决你的问题,请参考以下文章

Revit与Tekla二次开发交互拾取选择的简单对比

revit 二次开发之读取参数

Revit二次开发之十六 IExportContext的使用

Revit二次开发之 视图

Revit二次开发之载入族

revit 二次开发之基于族获得实例