下载app免费领取会员
在Revit API 论坛里看到了一个人在问,怎样实现在modeless对话框中
禁止删除操作,大概想了一下,可以通过下面3个步骤实现
1.在对话框显示的时候,复写删除命令
2.写一个外部命令来删除1中复写的命令
3.在对话框关闭后调用这个外部事件
下面是关键代码:
UIApplication uiapp = commandData.Application;
Window1 myWin = new Window1(uiapp);
myWin.Show();
return Result.Succeeded;
public partial class Window1 : Window
{
UIApplication uiapp = null;
ExEvent myEvent =null;
ExternalEvent myEventHandler = null;
public Window1()
{
InitializeComponent();
}
public Window1(UIApplication uiapp)
{
InitializeComponent();
AddInCommandBinding binding = uiapp.CreateAddInCommandBinding(RevitCommandId.LookupPostableCommandId(PostableCommand.Delete));
binding.Executed += Execute;
this.uiapp = uiapp;
myEvent = new ExEvent();
myEventHandler = ExternalEvent.Create(myEvent);
}
private void Execute(object sender, Autodesk.Revit.UI.Events.ExecutedEventArgs e)
{
MessageBox.Show("窗体关闭之前无法做删除操作!");
}
private void Window_Closed(object sender, EventArgs e)
{
myEventHandler.Raise();
}
}
public class ExEvent : IExternalEventHandler
{
public void Execute(UIApplication app)
{
app.RemoveAddInCommandBinding(RevitCommandId.LookupPostableCommandId(PostableCommand.Delete));
}
public string GetName()
{
return "test";
}
}
本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。
上一篇:二次开发教程:Revit开发通过Category设置构件颜色