Python 2 to Python 3 error

For this: if dialog.Show()
I’m getting an TypeError : No method matches given for show

I thought Show was in the taskdialog in Autodesk.Revit.UI which I have loaded: (from Autodesk.Revit.UI import *)

Found this thread: TaskDialog Problem in Revit 2023

But… mine’s not just a simple show…
if dialog.Show() == TaskDialogResult.Ok:

blergh… re-write time I think. :frowning:

I can’t even seem to change the button! I am stuck with a Cancel button.

What the output of dir(dialog)? - this will show methods and attributes associated with the object
perhaps

result = dialog.Show()
if result == TaskDialogResult.Ok:
...

Hey,

If you look at the documentation, you can see that there are various ‘constructors’.

I believe that we struggle in Python to define exactly which constructor we want to use?

So I think that in this instance, the constructor is only looking at the final option and therefore giving you a fail as it’s not what it was expecting…

Hopefully this is useful…

#based on Gavin Crump's code
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

# this fails
#result = TaskDialog.Show()

#this works
result = TaskDialog.Show('test', 'test', TaskDialogCommonButtons.Ok)

#as Mike Says, this is probably what you're after... i think?
if result == TaskDialogResult.Ok:
    OUT = 'woop'

else:
    OUT = 'so sad'
3 Likes

Some basic usage here Feedback: TaskDialogs

1 Like

My pop up now appears, thanks…
But the ISelectionFilter does not implement

row 29 , if I uncomment that I get the same error message

This was the code in IronPython

I want the pop up to say… “select view”.
The user clicks the OK button.
Then the user goes to Revit and only views can be selected.

This code works, perhaps have a look at its structure? :slight_smile:
It’s a lot easier for me if you post your code rather than screen shots…

Hope that helps,

Mark

#based on Gavin Crump's code
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

# this fails
#result = TaskDialog.Show()

#this works
result = TaskDialog.Show('test', 'test', TaskDialogCommonButtons.Ok)


#as Mike Says, this is probably what you're after... i think?
if result == TaskDialogResult.Ok:
    sel = uidoc.Selection
    ot = Selection.ObjectType.Element
    elemParamRef =  sel.PickObjects(ot, "click on anything")
    elements = [doc.GetElement(ePR) for ePR in elemParamRef]
    OUT = 'woop', elements

else:
    OUT = 'so sad'
1 Like

Ah, sorry, I normally do post the code but I was running out the door to a meeting.

Before reading your post

if TaskDialog.Show("Select viewport", "Click view", TaskDialogCommonButtons.Ok) == TaskDialogResult.Ok:
    el_ref = sel1.PickObject(obt1, CustomISelectionFilter("Viewports"), 'Pick an element of category')
    element = doc.GetElement(el_ref.ElementId) if el_ref else None
    OUT = element
else:
    OUT = None

After reading your post


if TaskDialog.Show('test', 'test', TaskDialogCommonButtons.Ok) == TaskDialogResult.Ok:
    el_ref =  sel1.PickObject(obt1, "click on anything")
    element = doc.GetElement(el_ref) if el_ref else None
    OUT = element
else:
    OUT = None

But I want to specify the object type. Viewports in this case.

The ISelectionFilter isn’t working.

Oh :frowning:

Annoying, you don’t have to use iselection, unfortunately not as satisfactory… but still does a job…

#credit to the forum for code

import clr
import sys
import System

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

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

from System.Collections.Generic import List

from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

pboxS=Autodesk.Revit.UI.Selection.PickBoxStyle.Enclosing

pickedBox = uidoc.Selection.PickObjects(ObjectType.Element, "Select viewports")

for element in pickedBox:
    e_id = element.ElementId
    a=doc.GetElement(e_id)
    #if element category is viewport, do stuff with them....
    #report elements which weren't viewports?

OUT=a
1 Like

Thanks… Honestly, as IronPython still works, I think I’m going to keep that for the moment.

Hopefully in Revit 25 this will be fixed?

3 Likes

it seems to be a limitation with CPython so we are waiting on them?

1 Like