Select all Model Elements (only) in the view

Hello all,

Happy new year!

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.

Can anyone provide me with a better solution?

Thank you.
Regards,

Atharva Purohit

@atharva.purohit466SX See if this helps:

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
1 Like

Hi Amol,

Thanks for the prompt reply.

As you can see in the image that the code is still giving the “piping systems”, which aren’t model elements.

regards,
ap

Hi, try with this

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)]
3 Likes

Hi Cyril,
Thanks for attempting!

But for a fact I know the view has 46 elements only, though your code is returning 86.

“Element” elements from the code cannot be selected.

@atharva.purohit466SX could you share here your rvt file?

Hi Kulkul,

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.

Can you help me out?
Regards,

try this:

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]
1 Like

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.

here’s the test file i’m using.

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")]

1 Like

Hi Kulkul,

It worked perfectly for the test file but in the actual file it still is giving unwanted “element”.

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.

Thanks again.
Regards,
AtharvaP

FYI, bounding box method is also quick. But if you still want to go with python. I will post another method in about 9 hours from now.

1 Like

@atharva.purohit466SX try this:

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"]]
4 Likes

It Worked!
Thank you Kulkul.
Though still there were one “elements”
but as discussed above, I turned off centerlines of all elements and it worked.

Marking as solution, right away!
Regards,
Atharva

Do you have any idea what is this?
(sorry for dragging it)
Was using in live working model.
Thanks,

No! You can check by typing that ID in Revit.

If you want clean solution you should share here your rvt file. Read the forum guidelines:

2 Likes

Got it.
(cannot share file due to valid reasons, sorry for that)

Thank you again.
ap

@atharva.purohit466SX
if you are on MEP model can be that filtering the elements which at least one connector can be a solution for you

4 Likes