如何创建Ribbon

  public class Class1 : IExternalApplication
    {
        public Result OnStartup(UIControlledApplication application)
        {
            //【1】第一步:创建一个RibbonTab
            application.CreateRibbonTab("面试插件");//new tab,输入内容是插件名
            //【2】第二步:在刚才的RibbonTab中创建UIPanel
            RibbonPanel rp = application.CreateRibbonPanel("面试插件", "钢筋");//分别为插件名和面板名
            //【3】第三步:指定程序集的名称以及所使用的类名
            //string assemblyPath = @"C:\Users\LILEI\source\repos\ExportList\bin\Debug\ExportList.dll";
            string assemblyPath = @"C:\Users\LILEI\source\repos\ColumnRebarCreat\bin\Debug\ColumnRebarCreat.dll";

            //当前程序集路径,当前程序路径

            //string revitExeLoaction = Process.GetCurrentProcess().MainModule.FileName;//可获得当前执行的exe的文件名。
            //TaskDialog.Show("当前程序路径", $"revitExeLoaction是{revitExeLoaction}");


            string classNameHelloRevitDemo = "ColumnRebarCreat.Class1";
            //【4】第四步:创建PushButton
            PushButtonData pbd = new PushButtonData("columnRebarCreat", "结构柱", assemblyPath, classNameHelloRevitDemo);
            //【4-1】讲pushButton添加到面板中

            PushButton pushButton = rp.AddItem(pbd) as PushButton;

            //【4-2】给按钮设置一个图片(大图标一般是32px,小图标一般是16px,格式可以是ico,png,jpg)
            // string imgPath = @"E:\b站课程\面向工程人员的revit二次开发课堂\08Revit二开之UIRibbon\圣诞节_棒棒糖.png";
            // pushButton.LargeImage = new BitmapImage(new Uri(imgPath));

            pushButton.LargeImage = new BitmapImage(new Uri("pack://application:,,,/UIButtonDemo;component/pic/柱.png", UriKind.Absolute));
            //【4-3】给按钮设置一个默认提示信息
            pushButton.ToolTip = "结构柱配筋";

            //////【4-4】再增加一个按钮
            //string assemblyPath2 = @" D:\daimo\DymoCreat\CreatRaber\bin\Debug\CreatRaber.dll";
            //string classHelloWorldDemo = "CreatTopBeamRebar.Class1";
            //PushButtonData pbdSecond = new PushButtonData("InnerNameWorld", "HelloWorld", assemblyPath2, classHelloWorldDemo);
            ////这句话的理解。1.注意rp.AddItem的返回值  2.RibbonItm与PushButton的转换
            //PushButton pushButtonSecond = rp.AddItem(pbdSecond) as PushButton;
            //// string imgPathSecond = @"E:\b站课程\面向工程人员的revit二次开发课堂\08Revit二开之UIRibbon\圣诞节_糖果.png";
            //pushButtonSecond.LargeImage = new BitmapImage(new Uri("pack://application:,,,/ExportList;component/pic/圣诞节_糖果.png", UriKind.Absolute));
            ////pushButtonSecond.LargeImage = new BitmapImage(new Uri(imgPathSecond));
            //pushButtonSecond.ToolTip = "HelloWorld";




            ////程序目录,以目录“C:\RevitRibbon”其中@用于转移字符
            //string addinPath = @"C:\RevitRibbon";
            ////程序集路径
            //string dllPth = addinPath + @"";
            ////按钮图标目录
            //string iconPath = @"C:\RevitRibbon\icon";
            ////插件选项卡名
            //string tabName = "插件名";
            ////面板底部文字提示
            //string panelName = "面板名";
            ////创建插件选项卡
            //application.CreateRibbonTab(tabName);
            ////添加顺序RibbonPanel(面板)——>SplitButton(按钮族)——>PushButton(按钮)
            ////新建面板
            //RibbonPanel panel = application.CreateRibbonPanel(tabName, panelName);

            ////实例一:按钮组
            //SplitButtonData splitButtonData = new SplitButtonData("wallSplit", "墙");
            ////添加到面板
            //SplitButton splitButton = panel.AddItem(splitButtonData) as SplitButton;
            ////按钮数据,注意“Rbn.com1”是执行按钮事件的响应类名
            //string tips1 = "用于在建筑模型中创建非结构墙";

            //PushButtonData pD1 = CreatePushButton("wall", "墙", @"C:\Users\LILEI\source\repos\HelloRevit\HelloRevit\bin\x64\Debug\HelloRevit.dll", "HelloRevit.Class1", iconPath, "1.png", tips1, "11.png");
            //splitButton.AddPushButton(pD1);
            ////按钮组添加第二个按钮
            //string tips2 = "用于在建筑模型中创建承重墙或剪力墙";
            //PushButtonData pD2 = CreatePushButton("SW", "墙:结构", @"C:\Users\LILEI\source\repos\HelloRevit\HelloRevit\bin\x64\Debug\HelloRevit.dll", "HelloRevit.Class1", iconPath, "2.png", tips2, "22.png");
            //splitButton.AddPushButton(pD2);

            ////示例2:下拉按钮,用于显示下拉命令的选项
            //PulldownButtonData pbData = new PulldownButtonData("Pulldown", "门");
            //PulldownButton pdBtn = panel.AddItem(pbData) as PulldownButton;
            //Uri uriLargeImage = new Uri(Path.Combine(iconPath, "3.png"), UriKind.Absolute);
            //pdBtn.LargeImage = new BitmapImage(uriLargeImage);
            ////添加命令按钮
            //PushButtonData pD3;
            //pD3 = CreatePushButton("Door", "门", dllPth, "Rbn.com3", iconPath, "3.png", "", "");
            //pdBtn.AddPushButton(pD3);

            ////示例3:命令按钮
            //RibbonPanel pane2 = application.CreateRibbonPanel(tabName, "按钮示例");
            //PushButtonData pD4;
            //pD4 = CreatePushButton("t1", "示例", dllPth, "Rbn.com3", iconPath, "4.png", "", "");
            //PushButtonData pD5;
            //pD5 = CreatePushButton("t2", "示例", dllPth, "Rbn.com3", iconPath, "5.png", "", "");
            //PushButtonData pD6;
            //pD6 = CreatePushButton("t3", "示例", dllPth, "Rbn.com3", iconPath, "5.png", "", "");
            //PushButtonData pD7;
            //pD7 = CreatePushButton("t4", "示例", dllPth, "Rbn.com3", iconPath, "5.png", "", "");
            //PushButtonData pD8;
            //pD8 = CreatePushButton("t5", "示例", dllPth, "Rbn.com3", iconPath, "5.png", "", "");
            //PushButtonData pD9;
            //pD9 = CreatePushButton("t6", "示例", dllPth, "Rbn.com3", iconPath, "5.png", "", "");
            ////每列一个按钮
            //pane2.AddItem(pD4);
            ////每列二个按钮
            //pane2.AddStackedItems(pD5, pD6);
            ////每列三个按钮
            //pane2.AddStackedItems(pD7, pD8, pD9);
            ////添加分隔符
            //pane2.AddSeparator();
            ////示例4:下拉组合框
            //ComboBoxData cbData = new ComboBoxData("下拉组合框");
            //ComboBoxMemberData cbMemberData;
            //cbMemberData = new ComboBoxMemberData("combox1", "下拉选项1");
            //ComboBox cBox = pane2.AddItem(cbData) as ComboBox;
            //cBox.AddItem(cbMemberData);
            return Result.Succeeded;
        }
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
    }
}
**------------恢复内容开始------------**
null
**------------恢复内容结束------------**

如何创建Ribbon

上一篇:抽象类-接口


下一篇:Android + Eclipse + NDK + cygwin配制