How to construct a TaskDialog?

I am wanting to construct a Taskdialog.

This seems straight forward when constructing single line commands. I’m more intrigued as a general python / class question.

I would have thought as a class I could construct a more complex TaskDialog, however I’m getting a TypeError: NoneType is not callable.

Could someone explain why this is the case ?

import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

# Method 1 - this works
#TaskDialog.Show("Title", "Main Content")

#Method 2 - TypeError : NoneType is not callable
dialog = TaskDialog("Header")
dialog.MainContent("Content") 
dialog.FooterText("Footer Text")

dialog.Show()

Many thanks all

J-P

You are calling it wrong. Try this:

import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

dialog = TaskDialog("Header")
dialog.MainInstruction = "Hello, Revit!"
dialog.MainContent = "This sample shows how to use a Revit task dialog to communicate with the user." "The command links below open additional task dialogs with more information."

dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "View information about the Revit installation")
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "View information about the active document")

dialog.CommonButtons = TaskDialogCommonButtons.Close;
dialog.DefaultButton = TaskDialogResult.Close;

dialog.FooterText = "<a href=\"http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975 \"> Click here for the Revit API Developer Center</a>"

dialog.Show()

#Assign your output to the OUT variable.
OUT = dialog

Cheers!

10 Likes

Thank you Konrad

That code works fine in IronPython2, but gives an error in CPython3:

Warning: TypeError : No method matches given arguments for Show: (<class ‘Autodesk.Revit.UI.TaskDialog’>) [’ File “”, line 17, in \n’]

Is it just me?

1 Like

CPython3 engine use a PythonNet bridge (for .Net) and the overloading (overload methods) in current version of PythonNet (2.5) don’t work very well, seem fix in future version (3.0)

2 Likes

The version for CPython Revit 2023

import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
from System.Reflection import BindingFlags

dialog = TaskDialog("Header")
dialog.MainInstruction = "Hello, Revit!"
dialog.MainContent = "This sample shows how to use a Revit task dialog to communicate with the user." "The command links below open additional task dialogs with more information."

dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "View information about the Revit installation")
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "View information about the active document")

dialog.CommonButtons = TaskDialogCommonButtons.Close;
dialog.DefaultButton = TaskDialogResult.Close;

dialog.FooterText = "<a href=\"http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975 \"> Click here for the Revit API Developer Center</a>"

#dialog.Show()
arguments = []
ResultDialog = clr.GetClrType(dialog.GetType()).InvokeMember("Show", BindingFlags.InvokeMethod , None, dialog, arguments)

#Assign your output to the OUT variable.
OUT = ResultDialog
1 Like