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'
This code works, perhaps have a look at its structure?
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'
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.
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