I need to select only model elements in the active view, but “all elements in active view” gives unwanted things like system types also.
This is the way i’m filtering out the unwanted currently but it seems to be very slow process.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
view = UnwrapElement(IN[0])
allElements = FilteredElementCollector(doc,view.Id).WhereElementIsNotElementType().ToElements()
filteredElements = []
for element in allElements:
if element.Category != None and element.Parameters.Size > 0 and element.HasPhases:
if element.Category.CategoryType == CategoryType.Model and (element.Category.SubCategories.Size > 0 or element.Category.CanAddSubcategory):
filteredElements.append(element)
OUT = filteredElements
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
view = UnwrapElement(IN[0])
allElements = FilteredElementCollector(doc,view.Id).WhereElementIsNotElementType().ToElements()
OUT = [x for x in allElements if not isinstance(x, MEPSystem)]
I cannot send the specific file as it is from an ongoing project but you can see I just tried it with a test file and the outcome is same. And this should work for all types of element, irrespective of being from mep/str.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
allElements = FilteredElementCollector(doc,view.Id).WhereElementIsNotElementType().ToElements()
OUT = [x for x in allElements if not isinstance(x, MEPSystem) and x.Category is not None and x.Category.CategoryType == CategoryType.Model]
I think we are close but still these two “element” elements are something which are not visible/ cannot be selected.
total elements should have been 7, but are 9 because of these notorious “element”.
I think they are somewhat related to pipes.
Because those are Center lines of MEP Elements. Change the last line to this:
OUT = [x for x in allElements if not isinstance(x, MEPSystem) and x.Category is not None and x.Category.CategoryType == CategoryType.Model and not x.Category.Name.Contains("Line")]
If you’re trying to get elements which has bbx then you can do the same using API. There are many examples on this forum, you can use forum search. Currently, I am not near my pc.
Okay Kulkul,
Thank you for your efforts, really appreciate.
In case of bounding box method, I think I’ll continue using the ootb node.
My thought was to collect the visible elements in the view without using bbx so as to reduce the machine effort, because my final file may have 20K elements.
Do let us know here, if you stumble upon any solution.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
view = UnwrapElement(IN[0])
allElements = FilteredElementCollector(doc,view.Id).WhereElementIsNotElementType().ToElements()
OUT = [x for x in allElements if x.get_BoundingBox(None) is not None and x.Category.CategoryType == CategoryType.Model and not x.Category.Name in ["Center Line","Cameras"]]