TaskDialog Problem in Revit 2023

Hello everyone, I’m trying to update a Dynamo script that worked fine in Revit 2021 to Revit 2023. I have a problem with the TaskDialog syntacs, with the Show() method. As seen in the image below. Python always gives me an error message with the show method, even though in the Revit api website that have no updates menitoned in this method. Any ideas what could be the problem here.

It has something to do with CPython and overloads.

So you need to fill out the default parameters for that call, I believe.

6 Likes

@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