この YouTube ビデオ ( https://www.youtube.com/watch?v=WU_D2qNnuGg&index=7&list=PLc_1PNcpnV5742XyF8z7xyL9OF8XJNYnv ) に示されている例に従っていました。これは、Revit API のフィルタリング方法が通常の繰り返しよりも優れていることを示しています。しかし、私のコードは反復法よりもかなり遅いです:
filter method-0.16 secs
iteration method-0.06 secs
フィルターメソッドを使用した私のコードは次のとおりです。
import Autodesk.Revit.DB as DB
doc=__revit__.ActiveUIDocument.Document
uidoc=__revit__.ActiveUIDocument
height_param_id=DB.ElementId(DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM)
height_param_prov=DB.ParameterValueProvider(height_param_id)
param_equality=DB.FilterNumericEquals() # equality class
height_value_rule=DB.FilterDoubleRule(height_param_prov,param_equality,10,1e-02)
param_filter=DB.ElementParameterFilter(height_value_rule)
# This program significantly slows down for the next line
walls=DB.FilteredElementCollector(doc)\
.WherePasses(param_filter)\
.ToElementIds()
uidoc.Selection.SetElementIds(walls)
繰り返しには、次のコードが使用されました。
from System.Collections.Generic import List
import Autodesk.Revit.DB as DB
doc=__revit__.ActiveUIDocument.Document
uidoc=__revit__.ActiveUIDocument
sheet_collector=DB.FilteredElementCollector(doc)\
.OfCategory(DB.BuiltInCategory\
.OST_Sheets)\
.WhereElementIsNotElementType()\
.ToElements()
walls=DB.FilteredElementCollector(doc)\
.OfCategory(DB.BuiltInCategory.OST_Walls)\
.WhereElementIsNotElementType()\
.ToElements()
tallwallsids=[]
for wall in walls:
heightp=wall.LookupParameter('Unconnected Height')
if heightp and heightp.AsDouble()==10:
tallwallsids.append(wall.Id)
uidoc.Selection.SetElementIds(List[DB.ElementId](tallwallsids))