We talked about creating a comprehensive TaskDialog example manually, utilizing some TaskDialog shortcuts to make simple TaskDialog variations, and using TaskDialoger of RevitAddinWizard to create any TaskDialog instances we like automatically in a configurable and flexible way before.
TaskDialog of Revit API - 1: A Comprehensive TaskDialog Example
TaskDialog of Revit API - 2: Some TaskDialog Shortcuts
TaskDialog of Revit API - 3: TaskDialoger
The only thing is that they are all about C#. VB.NET developers might feel a bit uncared-for. Don’t worry! We will make it up in this article.
Let’s put aside concepts and backgrounds here and go into coding directly:
Public Shared Function CreateTaskDialog() As Autodesk.Revit.UI.TaskDialogResult
' Constructor stuff
Dim td As New TaskDialog("TaskDialog Demonstration by Spiderinnet")
' Nice to set stuffs
td.Id = "ID_TaskDialog_Demonstration_by_Spiderinnet"
td.MainIcon = Autodesk.Revit.UI.TaskDialogIcon.TaskDialogIconWarning
td.Title = "This is 'Title'."
td.TitleAutoPrefix = True
td.AllowCancellation = True
' Message related stuffs
td.MainInstruction = "This is 'MainInstruction'."
td.MainContent = "This is 'MainContent'."
td.FooterText = "This is 'FooterText'."
td.ExpandedContent = "This is 'ExpandedContent'." & vbLf & "Line1: blar blar..." & vbLf & "Line2: blar blar..." & vbLf & "Line3: blar blar..."
' VerificationText stuff
td.VerificationText = "This is 'VerificationText'."
' Command link stuffs
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "This is 'CommandLink1'.")
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "This is 'CommandLink2'.")
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink3, "This is 'CommandLink3'.")
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink4, "This is 'CommandLink4'.")
' Common button stuffs
td.CommonButtons = Autodesk.Revit.UI.TaskDialogCommonButtons.Cancel Or Autodesk.Revit.UI.TaskDialogCommonButtons.Ok Or Autodesk.Revit.UI.TaskDialogCommonButtons.Close Or Autodesk.Revit.UI.TaskDialogCommonButtons.No Or Autodesk.Revit.UI.TaskDialogCommonButtons.Yes Or Autodesk.Revit.UI.TaskDialogCommonButtons.Retry Or Autodesk.Revit.UI.TaskDialogCommonButtons.None
td.DefaultButton = Autodesk.Revit.UI.TaskDialogResult.Ok
' Dialog showup stuffs
Dim tdRes As Autodesk.Revit.UI.TaskDialogResult = td.Show()
Return tdRes
End Function
If the above method is called in an external command and in turn triggered by a ribbon item, PushButton for example, a TaskDialog like the following will appear:
In terms of what the TitleAutoPrefix property really points to, we have talked about that in detail before and will not repeat here.
If the little tiny thing ‘See details’ is clicked, the TaskDialog will be expanded and the ExpandedContent show up:
The VB.NET code here is not so much different than the one in C# we demenstrated before, but wait a moment, the Revit TaskDialog API & VB.NET do have a quirk that we’d better keep in mind.
The first is that fullly qualified type name had to be used for the enum value TaskDialogIcon.TaskDialogIconWarning though in the complete code the namespace Autodesk.Revit.UI had already been imported beforehand. Otherwise, a compiler error like the following would just occur:
Error 1 ‘TaskDialogIcon’ is not accessible in this context because it is 'Friend'.
Not sure whether the TaskDialogIcon in the real Revit API implementation is really a ‘Friend’, but the same code worked perfectly well in C#. Some tools could be used to hack this out but that is not something I like. Please feel free to give it a try if cannot help your curiousity.
The same weird behavior was also demonstrated by the types TaskDialogCommonButtons and TaskDialogResult.
Now TaskDialoger of RevitAddinWizard can also create the VB.NET code automatically.
Recent Comments