Hi All,
I use the below script for select object by Category.
My problem is select object is not highlighted when i select the object in Revit.
please give me a suggestion.
Thanks in advance.
#Copyright(c) 2017, john pierson
# @60secondrevit, http://sixtysecondrevit.com
#Thanks to Dimitar and Troy Gates for Guidance
#and this blog http://pythoncvc.net/?p=116
#Edited by Sean Page, 12/9/2020 to accept list of categories
import clr
import msvcrt
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
TaskDialog.Show('Isolated Selection','Pick elements in desired order, then press ESC to finish')
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element
class CustomISelectionFilter(Selection.ISelectionFilter):
def __init__(self, nom_categorie):
self.nom_categorie = nom_categorie
def AllowElement(self, e):
if self.nom_categorie.Contains(e.Category.Name):
#if e.Category.Name == self.nom_categorie:
return True
else:
return False
def AllowReference(self, ref, point):
return true
msg1 = 'Pick elements in desired order then press ESC to finish.'
out1 = []
flag = True
while flag:
try:
el1 = doc.GetElement(sel1.PickObject(obt1,CustomISelectionFilter(IN[0]), msg1).ElementId)
out1.append(el1.ToDSType(True))
except:
flag = False
OUT = out1
Hello, here is the revised code
#Copyright(c) 2017, john pierson
# @60secondrevit, http://sixtysecondrevit.com
# Thanks to Dimitar and Troy Gates for Guidance
# and this blog http://pythoncvc.net/?p=116
# Edited by Sean Page, 12/9/2020 to accept list of categories
# Edited by C.POUPIN
import clr
import System
from System.Collections.Generic import List
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
TaskDialog.Show('Isolated Selection','Pick elements in desired order, then press ESC to finish')
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element
class CustomISelectionFilter(Selection.ISelectionFilter):
def __init__(self, lstCat):
self.lstCatId = [ElementId(bic) for bic in lstCat]
def AllowElement(self, e):
if e.Category.Id in self.lstCatId:
return True
else:
return False
def AllowReference(self, ref, point):
return true
toList = lambda x : x if hasattr(x, '__iter__') else [x]
#Preparing input from dynamo to revit
lstDSCat = toList(IN[0])
lstCat = [System.Enum.ToObject(BuiltInCategory, x.Id) for x in lstDSCat]
filterObj = CustomISelectionFilter(lstCat)
msg1 = 'Pick elements in desired order then press ESC to finish.'
out1 = List[ElementId]()
flag = True
while flag:
try:
el1 = doc.GetElement(sel1.PickObject(obt1, filterObj, msg1))
out1.Add(el1.Id)
except Exception as ex:
print(ex)
flag = False
sel1.SetElementIds(out1)
OUT = [doc.GetElement(xId) for xId in out1]
1 Like
Hi there c.poupin
I was reading this post and noted this solves a problem similar to mine.
I’m not an advanced python user, so this script is a bit complicated for me.
I have a similar problem, only I need to highlight just one element whose “Id” I already know.
Could you help me: Which part of this python script can I take in order to solve this?
Hi,
here an example
import clr
import System
from System.Collections.Generic import List
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI.Selection import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
elemId = IN[0]
if isinstance(elemId, (int, System.Int32, System.Int64)):
uidoc.Selection.SetElementIds(List[ElementId]([ElementId(elemId)]))
elif isinstance(elemIdInteger, ElementId):
uidoc.Selection.SetElementIds(List[ElementId]([elemId]))
else:
pass
OUT = elemId