TaskDialog Problem in Revit 2023

@Amr.Omara
If you have little experience with .Net Reflection, this can be useful to get around problems of Overloading

an example

import sys
import clr
import System
from System.Collections.Generic import List

clr.AddReference('RevitAPI')
import Autodesk.Revit.DB as DB

#clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import (TaskDialog, TaskDialogCommonButtons,
                               TaskDialogCommandLinkId, TaskDialogResult)

title = 'Task Dialog Title'
dialog = TaskDialog(title)

# Properties
dialog.MainInstruction = 'Text Header'
dialog.MainContent = 'Text Content'
dialog.FooterText = 'Footer Text'
dialog.VerificationText = 'Verification Text'
# dialog.ExpandedContent = expanded_content
# Add Button
dialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Yes

# Set Default Button
dialog.DefaultButton = getattr(TaskDialogResult, "None")

# Add Command Link
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
                      'Command Button Text',
                      'Command Button Sub Text')
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
                      'Command Button Text 2',
                      'Command Button Sub Text 2')

#result = dialog.Show()
# Example 1 with InvokeMember
arguments = []
invokeObj_1 = clr.GetClrType(dialog.GetType()).InvokeMember("Show", BindingFlags.InvokeMethod , None, dialog, arguments)
# OR 
# Example 1 with Invoke
filter = System.Predicate[System.Object](lambda m : m.Name == "Show" and len(m.GetParameters()) == 0 )
invokeMethod = List[System.Reflection.MethodInfo](clr.GetClrType(dialog.GetType()).GetMethods()).Find(filter)
invokeObj_2 = invokeMethod.Invoke(dialog, None)
#
OUT = invokeObj_1, invokeObj_2
7 Likes