下載app免費領取會員
在Revit API 論壇里看到了一個人在問,怎樣實現(xiàn)在modeless對話框中
禁止刪除操作,大概想了一下,可以通過下面3個步驟實現(xiàn)
1.在對話框顯示的時候,復寫刪除命令
2.寫一個外部命令來刪除1中復寫的命令
3.在對話框關閉后調(diào)用這個外部事件
下面是關鍵代碼:
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";
}
}
本文版權歸腿腿教學網(wǎng)及原創(chuàng)作者所有,未經(jīng)授權,謝絕轉載。
上一篇:二次開發(fā)教程:Revit開發(fā)通過Category設置構件顏色