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();
}
}
}

Revit二次开发示例:DisableCommand的更多相关文章

  1. Revit二次开发示例:HelloRevit

    本示例实现Revit和Revit打开的文件的相关信息. #region Namespaces using System; using System.Collections.Generic; using ...

  2. Revit二次开发示例:EventsMonitor

    在该示例中,插件在Revit启动时弹出事件监控选择界面,供用户设置,也可在添加的Ribbon界面完成设置.当Revit进行相应操作时,弹出窗体会记录事件时间和名称. #region Namespace ...

  3. Revit二次开发示例:ErrorHandling

    本示例介绍了Revit的错误处理.   #region Namespaces using System; using System.Collections.Generic; using Autodes ...

  4. Revit二次开发示例:ChangesMonitor

    在本示例中,程序监控Revit打开文件事件,并在创建的窗体中更新文件信息.   #region Namespaces using System; using System.Collections.Ge ...

  5. Revit二次开发示例:AutoStamp

    该示例中,在Revit启动时添加打印事件,在打印时向模型添加水印,打印完成后删除该水印.   #region Namespaces using System; using System.Collect ...

  6. Revit二次开发示例:ModelessForm_ExternalEvent

    使用Idling事件处理插件任务. #region Namespaces using System; using System.Collections.Generic; using Autodesk. ...

  7. Revit二次开发示例:Journaling

    关于Revit Journal读写的例子.   #region Namespaces using System; using System.Collections.Generic; using Sys ...

  8. Revit二次开发示例:DesignOptions

    本例只要演示Revit的类过滤器的用法,在对话框中显示DesignOption元素. #region Namespaces using System; using System.Collections ...

  9. Revit二次开发示例:DeleteObject

    在本例中,通过命令可以删除选中的元素. 需要注意的是要在代码中加入Transaction,否则的话会出现Modifying  is forbidden because the document has ...

随机推荐

  1. [Effective JavaScript 笔记]第57条:使用结构类型设计灵活的接口

    想象创建wiki的库.wiki网站包含用户可以交互式地创建.删除和修改的内容.许多wiki都以简单.基于文本标记语言创建内容为特色.通常,这些标记语言只提供了HTML可用功能的一个子集,但是却有一个更 ...

  2. unity3d进行脚本资源打包加载

    原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...

  3. 转:github使用教程(重装系统后遇到问题该文章帮我解决了)

    github简单使用教程 时间:2012 年 5 月 29 日 6 条评论 分类:学习笔记 , 网络 , 软件 目录 1.注册账户以及创建仓库 2.安装客户端msysgit 3.配置Git 4.提交. ...

  4. HTML 快速入门

     最近帮朋友研究作一个网站,虽然对很多人来说这是很简单的事情,但是对我来说却比较复杂!废话不多讲了,看看我找的HTML快速入门,说不定也会对你有帮助! 一. HTML 的基本概念 HTML ( Hyp ...

  5. poj1789 Truck History

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20768   Accepted: 8045 De ...

  6. Android-自定义meta-data扩展数据

    在接入第三方渠道SDK的时候,经常会看到其配置文件AndroidManifest.xml有类似如下的定义: [html] view plaincopy <!-- appid --> < ...

  7. 【云计算】Docker删除名称为none的Image镜像

    先上删除命令: docker images|grep none|awk '{print $3 }'|xargs docker rmi docker强制批量删除none的image镜像   真是有段时间 ...

  8. Nth to Last Node in List

    Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Exam ...

  9. css 属性

    部分属性在firefox 中添加-moz- safari 以及chrome  加上-webkit- opera 加上-o- ie9里可能需要-ms- jquery  中的css  操作  和一般的cs ...

  10. 多表利用DIH批量导入数据并建立索引注意事项

    如果希望同时对多个表进行全文检索,那我们该如何处理呢?利用DIH导入数据并建立索引时.schema.xml中配置了uniqueKey为id <uniqueKey>id</unique ...