Hi. This is my first Question here at the forum so please forgive me for not being smart enough to format the attached code…
I have a Python node inside Dynamo 2.12.1 with a simple Python code to show a Task Dialog.
The code works fine if the Python node is set to use IronPython2 but it will not work if I change to CPython3.
The code I use is:
# This code will work with IronPython2 but not with CPython3
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog, TaskDialogResult, TaskDialogCommonButtons
main_dialog = TaskDialog("This is the Title")
main_dialog.MainInstruction = "This is the Main Instruction"
main_dialog.MainContent = "This is the Main Content"
main_dialog.FooterText = "This is the Footer Text"
main_dialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel
result = main_dialog.Show()
OUT = result
With IronPython the code above will result in a Task Dialog as intended.
With CPython3 the code will result in a error message as in picture below:
The only way I can make a Task Dialog show up with CPython3 is if I use this overloaded version of Show:
Show(String, String, TaskDialogCommonButtons)
[Show Method (String, String, TaskDialogCommonButtons)]
But then I cant add a FooterText, MainContent etc since there are no overloaded version with them.
The code below will work with CPython3 but is limited to show title, Main Instruction and Buttons:
# This works in CPython3 but the Task dialog can only show Title, Main instruction and common buttons.
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog, TaskDialogResult, TaskDialogCommonButtons
title = "This is the Title"
main_instruction = "This is the Main Instruction."
buttons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel
result = TaskDialog.Show(title, main_instruction, buttons)
OUT = result
Question:
Why will the first code work with IronPython2 but not with CPython3 and how can I create a Task Dialog with more properties than title, Main Instruction and Buttons in CPython3 ?
Thanks @Ewan_Opie and @c.poupin
I added the InvokeMember method as suggested in the link and now it works.
(Thanks to @Draxl_Andreas as well)
The final code is as follows:
import clr
import System
from System.Reflection import BindingFlags
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog, TaskDialogCommonButtons, TaskDialogResult
main_dialog = TaskDialog("This is the Title")
main_dialog.MainInstruction = "This is the Main Instruction"
main_dialog.MainContent = "This is the Main Content"
main_dialog.FooterText = "This is the Footer Text"
main_dialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel
arguments = []
result = clr.GetClrType(main_dialog.GetType()).InvokeMember("Show", BindingFlags.InvokeMethod , None, main_dialog, arguments)
OUT = result
Is there something wrong in my settings?
Using show.dialog worked also in Cpython3 but some how not anymore.
I use Windows 10, Revit 2023.1 with pyRevit on my local disk.
What should be causing this error? Windows update? Is it a security-issue? Is a Dynamo-package causing this error? I do not know. I’m not an IT-er.
Still don’t know why this script doesn’t work in CPython3.
I created a new script with only this code and it doesn’t work in Revit 2022/2023/2024.
import clr
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog
msg = "Works with CPython3"
#show the message dialog box...
TaskDialog.Show("Bericht", msg)
#return a result in Dynamo...
OUT = msg
Who know what’s wrong?
Edit:
It’s getting even stranger. After creating a new and empty script I see errors.
The last one says:
I’m using also pyRevit 4.8.13