Hello,
I want to collect ducts at level 1, but I got empty result…what’s wrong with my code?
import clr
import Revit
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
bip = BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM
provider = ParameterValueProvider(ElementId(bip))
evaluator = FilterStringEquals()
rule = FilterStringRule(provider, evaluator, 'Level 1', False)
elementfilter = ElementParameterFilter(rule)
run = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DuctCurves).WherePasses(elementfilter).WhereElementIsNotElementType().ToElements()
OUT = run
1 Like
@newshunhk ,
you are looking for that ?
import clr
# Import RevitAPI Classes
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
toList = lambda x : x if hasattr(x, '__iter__') else [x]
#Preparing input from dynamo to revit
pipes = toList(UnwrapElement(IN[0]))
def GetPipesLevel(item):
assert sdkNumber > 2021, "This Script is only Compatible with Revit 2022 and higher"
UIunit = Document.GetUnits(doc).GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
Zvalue = item.Location.Curve.Origin.ToPoint().Z*1.00
convertTo = UnitUtils.ConvertToInternalUnits(Zvalue, UIunit)
return doc.GetElement(Autodesk.Revit.DB.Level.GetNearestLevelId(doc,UnitUtils.ConvertToInternalUnits(convertTo,UIunit)))
OUT = [GetPipesLevel(m) for m in pipes]
the script has to be cleaned up, i just replaced curves by pipes
1 Like
no.
I want to collect all ducts at Level 1 using python, I can collect all ducts, but I wanna filter the reference level “Level 1” as well.
I tried to follow this blog and modify myself, but fail.
https://thebuildingcoder.typepad.com/blog/2010/06/parameter-filter.html
1 Like
@newshunhk
try to create a second part
levels = [GetPipesLevel(m) for m in pipes]
OUT = []
for i in levels:
OUT.append(i.BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM)
#provider = ParameterValueProvider(ElementId(pips))
#rule = FilterStringRule(provider, evaluator, 'Level 1', False)
this is not what I want sorry
maybe my question is not clear…
anyway thanks
I think I know where is the mistake
the builtin parameter of reference level of structural framing and duct is different
I changed
BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM
to
BuiltInParameter.RBS_START_LEVEL_PARAM
then I fixed the problem
1 Like