コード例 #1
0
ファイル: Labs6.cs プロジェクト: ezhangle/AdnRevitApiLabsXtra
        void DismissDialog(
            object sender,
            DialogBoxShowingEventArgs e)
        {
            TaskDialogShowingEventArgs te = e as TaskDialogShowingEventArgs;

            if (te != null)
            {
                if (te.DialogId == "TaskDialog_Family_Already_Exists")
                {
                    // In this task dialog, 1001 maps to the first button,
                    // which is the "override the existing version"
                    int iReturn = 1001;

                    // Set OverrideResult argument to 1001 mimic clicking the first button.
                    e.OverrideResult(iReturn);

                    // 1002 maps the second button in this dialog.
                    // DialogResult.Cancel maps to the cancel button.
                }
            }
            else
            {
                MessageBoxShowingEventArgs msgArgs = e as MessageBoxShowingEventArgs;
                if (null != msgArgs) // this is a message box
                {
                    //e.OverrideResult( (int) WinForms.DialogResult.Yes );
                    //Debug.Print( "Dialog id is {0}\r\nMessage is {1}",
                    //  msgArgs.HelpId, msgArgs.Message ); // Revit 2016

                    e.OverrideResult((int)WinForms.DialogResult.Yes);
                    Debug.Print("Dialog id is {0}\r\nMessage is {1}",
                                msgArgs.DialogId, msgArgs.Message); // Revit 2017
                }
                else // this is some other dialog, for example, element property dialog.
                {
                    // Use the HelpId to identify the dialog.
                    //if( e.HelpId == 1002 ) // Element property dialog's HelpId is 1002 in Revit 2016 and earlier

                    if (e.DialogId.Equals("1002")) // What is the corresponding Element property dialog DialogId?
                    {
                        e.OverrideResult((int)WinForms.DialogResult.No);
                        Debug.Print(
                            "We just dismissed the element property dialog "
                            + "and set the return value to No.");
                    }
                }
            }
        }
コード例 #2
0
        public static void HandleDialogBoxShowing(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e)
        {
            TaskDialogShowingEventArgs taskEvent = e as TaskDialogShowingEventArgs;
            MessageBoxShowingEventArgs msgEvent  = e as MessageBoxShowingEventArgs;

            try
            {
                if (taskEvent != null)
                {
                    //  Click OK
                    string dialogId = taskEvent.DialogId;
                    int    helpId   = taskEvent.HelpId;
                    string message  = taskEvent.Message;
                    LogFileManager.AppendLog("TaskDialog Message", message);
                    taskEvent.OverrideResult((int)WinForms.DialogResult.OK);
                }
                else if (msgEvent != null)
                {
                    int    okid       = (int)WinForms.DialogResult.OK;
                    int    dialogType = msgEvent.DialogType;
                    int    helpId     = msgEvent.HelpId;
                    string message    = msgEvent.Message;
                    LogFileManager.AppendLog("MessageBox Message", message);
                    msgEvent.OverrideResult(okid);
                }
                else
                {
                    LogFileManager.AppendLog("Windows MessageBox Id", e.HelpId.ToString());
                    e.OverrideResult(1);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }