首页/技术分享

二次开发教程:Revit开发实现在modeless对话框中无法删除构件

发布于:2019-08-26 16:47:24
7069人 分享

在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";

        }

    }

转载请注明来源本文地址:https://www.tuituisoft/blog/3485.html

上一篇:

二次开发教程:Revit开发通过Category设置构件颜色

下一篇:

二次开发教程:Revit开发之调用过滤器设置窗体设置过滤器