Revit二次开发之利用AdWindows在任意选项卡上创建按钮

为了达到目的我们又不得不需要AdWindows.dll这个类库的帮助了——正所谓  夏日消溶,江河横溢,人或为鱼鳖。我们也玩转一下Revit——上代码!

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using System.Windows.Media.Imaging;

namespace HelloWorld
{
      [Transaction(TransactionMode.Manual)]
      [Regeneration(RegenerationOption.Manual)]
      public class Test : IExternalApplication
      {       
            public Result OnStartup(UIControlledApplication application)
            {
                  foreach (Autodesk.Windows.RibbonTab tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs)
                  {
                        if (tab.Id == "Modify")//将按钮嵌入到修改选项卡上
                        {

                              Autodesk.Windows.RibbonPanel ADNPanel = new Autodesk.Windows.RibbonPanel();
                              Autodesk.Windows.RibbonPanelSource ADNSource = new Autodesk.Windows.RibbonPanelSource();
                              ADNSource.Id = "ID_NRC_Panel";
                              ADNSource.Name = "Navisworks";
                              ADNPanel.Source = ADNSource;
                              Autodesk.Windows.RibbonButton button = new Autodesk.Windows.RibbonButton();
                              button.Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"C:\ProgramData\Autodesk\Revit\Addins\2016\BIM工具箱\BIM\Image\NRC.ico"));
                              button.LargeImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"C:\ProgramData\Autodesk\Revit\Addins\2016\BIM工具箱\BIM\Image\NRC.ico"));
                              button.ShowImage = true;
                              button.Size = Autodesk.Windows.RibbonItemSize.Large;
                              button.ShowText = true;
                              button.Id = "ID_NRC_Button";
                              button.Name = "NRC";
                              button.Text = "Navis" + "\n" + "works";
                              button.IsEnabled = true;
                              button.IsVisible = true;
                              button.IsCheckable = true;//如果不设置,则按钮不可用,也不知是否为天生的Bug等有时间再解决喽
                              button.Orientation = System.Windows.Controls.Orientation.Vertical;
                              ADNPanel.Source.Items.Add(button);
                              Autodesk.Windows.ComponentManager.UIElementActivated += new EventHandler(ComponentManager_UIElementActivated);
                              tab.Panels.Add(ADNPanel);

                              break;
                        }
                  }
                
                  return Result.Succeeded;
            }
            //按钮触发事件,可以也逻辑代码,允许开启事务
            void ComponentManager_UIElementActivated(object sender, Autodesk.Windows.UIElementActivatedEventA rgs e)
            {
                  if (e != null && e.Item != null && e.Item.Id != null && e.Item.Id == "ID_NRC_Button")
                  {


                        try
                        {
                             //逻辑代码
                        }
                        catch { }
                  }

            }
            public Result OnShutdown(UIControlledApplication application)
            {
                  return Result.Succeeded;
            }
      }

}



转自;http://blog.sina.com.cn/s/blog_16796559b0102y8dq.html

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值