Revit二次开发-忽略警告对话框

Revit二次开发-忽略警告对话框

在Revit二次开发的工作中,或许会遇见这样的需求,根据Id选取Element 但是如果在当前View中未显示该Element 就会出现以下警告对话框,那么Api是否提供了相关接口来处理该对话框呢,答案是肯定的。
在这里插入图片描述

public event EventHandler<DialogBoxShowingEventArgs> DialogBoxShowing

这个事件用于处理各种对话框,在帮助手册下也提供了一段Demo供我们参考。

public class Application_DialogBoxShowing : IExternalApplication
{
    // Implement the OnStartup method to register events when Revit starts.
    public Result OnStartup(UIControlledApplication application)
    {
        // Register related events
        application.DialogBoxShowing += 
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // Implement this method to unregister the subscribed events when Revit exits.
    public Result OnShutdown(UIControlledApplication application)
    {
        // unregister events
        application.DialogBoxShowing -= 
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // The DialogBoxShowing event handler, which allow you to 
    // do some work before the dialog shows
    void AppDialogShowing(object sender, DialogBoxShowingEventArgs args)
    {
        // Get the string id of the showing dialog
        String dialogId = args.DialogId;

        // Format the prompt information string
        String promptInfo = "A Revit dialog will be opened.\n";
        promptInfo += "The DialogId of this dialog is " + dialogId + "\n";
        promptInfo += "If you don't want the dialog to open, please press cancel button";

        // Show the prompt message, and allow the user to close the dialog directly.
        TaskDialog taskDialog = new TaskDialog("Revit");
        taskDialog.Id = "Customer DialogId";
        taskDialog.MainContent = promptInfo;
        TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Ok | 
                                            TaskDialogCommonButtons.Cancel;
        taskDialog.CommonButtons = buttons;
        TaskDialogResult result = taskDialog.Show();
        if (TaskDialogResult.Cancel == result)
        {
            // Do not show the Revit dialog
            args.OverrideResult(1);
        }
        else
        {
            // Continue to show the Revit dialog
            args.OverrideResult(0);
        }
    }
}
 public class TestDemo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //相关业务代码 假设会出现对话框

            commandData.Application.DialogBoxShowing += Application_DialogBoxShowing; ;
            return Result.Succeeded;
        }

        private void Application_DialogBoxShowing(object sender, DialogBoxShowingEventArgs e)
        {
            e.OverrideResult(1); // 非0值会处理掉不会显示 0会显示
        }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值