-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DialogBoxResolver
to cancel dialog box before revit initialization
- Loading branch information
Showing
7 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>1.4.0-alpha.1</Version> | ||
<Version>1.4.0-beta</Version> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
ricaun.RevitTest.Application/Revit/Utils/DialogBoxResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Autodesk.Revit.UI; | ||
using System; | ||
|
||
namespace ricaun.RevitTest.Application.Revit.Utils | ||
{ | ||
/// <summary> | ||
/// DialogBoxResolver resolve the dialog box by DialogId and override the result to cancel. | ||
/// </summary> | ||
/// <remarks>The resolver only works before Revit initialize.</remarks> | ||
public class DialogBoxResolver : IDisposable | ||
{ | ||
private readonly UIControlledApplication application; | ||
private readonly string[] TaskDialogIds; | ||
public DialogBoxResolver(UIControlledApplication application) | ||
{ | ||
this.application = application; | ||
this.TaskDialogIds = new string[] | ||
{ | ||
"TaskDialog_License_Current_Status_Demo_Mode", // Viewer Mode | ||
"TaskDialog_DNSMTemplate" // Revit Warning | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Initialize the events to resolve the dialog box. | ||
/// </summary> | ||
/// <remarks>The Initialize is ignored if the <see cref="Autodesk.Revit.UI.UIControlledApplication.IsLateAddinLoading"/>.</remarks> | ||
public virtual void Initialize() | ||
{ | ||
if (this.application.IsLateAddinLoading) return; | ||
Dispose(); | ||
this.application.DialogBoxShowing += OnDialogBoxShowing; | ||
this.application.ControlledApplication.ApplicationInitialized += OnApplicationInitialized; | ||
} | ||
|
||
/// <summary> | ||
/// Dispose the events. | ||
/// </summary> | ||
public virtual void Dispose() | ||
{ | ||
this.application.DialogBoxShowing -= OnDialogBoxShowing; | ||
this.application.ControlledApplication.ApplicationInitialized -= OnApplicationInitialized; | ||
} | ||
|
||
private void OnDialogBoxShowing(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e) | ||
{ | ||
if (TaskDialogIds is null) return; | ||
foreach (var dialogId in TaskDialogIds) | ||
{ | ||
if (dialogId == e.DialogId) | ||
{ | ||
Console.WriteLine($"{nameof(DialogBoxResolver)}: [{e.DialogId}]"); | ||
e.OverrideResult((int)TaskDialogResult.Cancel); | ||
return; | ||
} | ||
} | ||
} | ||
private void OnApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e) | ||
{ | ||
Dispose(); | ||
} | ||
} | ||
|
||
} |
Binary file modified
BIN
+2.2 KB
(100%)
ricaun.RevitTest.Console/Resources/ricaun.RevitTest.Application.bundle.zip
Binary file not shown.
Binary file modified
BIN
+2.37 KB
(100%)
ricaun.RevitTest.TestAdapter/Resources/net48/ricaun.RevitTest.Console.zip
Binary file not shown.
Binary file modified
BIN
+2.3 KB
(100%)
ricaun.RevitTest.TestAdapter/Resources/net8.0-windows/ricaun.RevitTest.Console.zip
Binary file not shown.