zoukankan      html  css  js  c++  java
  • Revit二次开发示例:DisableCommand


    Revit API 不支持调用Revit内部命令,但可以用RevitCommandId重写它们(包含任意选项卡,菜单和右键命令)。使用RevitCommandId.LookupCommandId()可以提供查询和获取命令的ID,然后用CreateAddInCommandBinding()来创建绑定一个AddInCommandBinding实例,通过Executed和CanExecute事件来完成重写内部命令。

    下面是一个具体的例子:
     

    #region Namespaces
    using System;
    using System.Collections.Generic;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    #endregion
    
    namespace DisableCommand
    {
        [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
        [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
        [Autodesk.Revit.Attributes.Journaling(JournalingMode.NoCommandData)]
        class App : IExternalApplication
        {
            static String s_commandToDisable = "ID_EDIT_DESIGNOPTIONS";
            static RevitCommandId s_commandId;
    
            public Result OnStartup(UIControlledApplication a)
            {
                s_commandId = RevitCommandId.LookupCommandId(s_commandToDisable);
    
                if (!s_commandId.CanHaveBinding)
                {
                    ShowDialog("Error", "The target command" + s_commandToDisable +
                        " selected for disabling cannot be overridden");
                    return Result.Failed;
                }
    
                try
                {
                    AddInCommandBinding commandBinding = a.CreateAddInCommandBinding(s_commandId);
                    commandBinding.Executed += commandBinding_Executed;
                }
                catch (Exception)
                {
    
                    ShowDialog("Error", "This add-in is unable to disable the target command " + s_commandToDisable +
                        "; most likly another add-in has overridden this command.");
                }
    
                return Result.Succeeded;
            }
    
            void commandBinding_Executed(object sender, Autodesk.Revit.UI.Events.ExecutedEventArgs e)
            {
                ShowDialog("Disabled", "Use of this command has been disabled.");
            }
    
            public Result OnShutdown(UIControlledApplication a)
            {
                if (s_commandId.HasBinding)
                    a.RemoveAddInCommandBinding(s_commandId);
    
                return Result.Succeeded;
            }
    
            private static void ShowDialog(string title, string message)
            {
                TaskDialog td = new TaskDialog(title)
                {
                    MainInstruction = message,
                    TitleAutoPrefix = false
                };
                td.Show();
            }
        }
    }

  • 相关阅读:
    MongoDB 分片机制
    MongoDb的“not master and slaveok=false”错误及解决方法
    MongoDB 副本集复制配置
    spring,mybatis整合配置文件
    Tomcat-正统的类加载器架构
    CSS3系列三(与背景边框相关样式 、变形处理、动画效果)
    如果您想省略JS里的分号,了解一下JS的分号插入原理吧
    CSS3系列二(媒体支持、文字与字体相关样式、盒相关样式)
    CSS3系列一(概述、选择器、使用选择器插入内容)
    HTML5系列四(WebWorker、地理定位)
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3607830.html
Copyright © 2011-2022 走看看