How to list only elements that are "Visible" in a view?

How to list only elements that are "Visible" in a view?

waleed.hany
Contributor Contributor
2,470 Views
3 Replies
Message 1 of 4

How to list only elements that are "Visible" in a view?

waleed.hany
Contributor
Contributor

How to list elements that are only visible in a view (ex. elevation or section)?
I tried : 

FilteredElementCollector allElementsInView = new FilteredElementCollector(Doc, view.Id);
IList<Element> elementsInView = allElementsInView.ToElements();

However the result includes elements that are not visible in the view, as an example, if the target is to filter all walls that appear in elevations, the return result from filtering also includes walls that are hidden behind the front (Elevation) walls.
Is there a way to obtain only the elements that "appear" in the view ?

Thanks. 

Accepted solutions (1)
2,471 Views
3 Replies
Replies (3)
Message 2 of 4

IbrahimNaeem
Advocate
Advocate

Elevations, Sections, and kinda types of views have a depth of view and that's why these elements come up in your list. Please allow me to rephrase your question to be "how to avoid listing obscured objects in a view?"

 

Message 3 of 4

785398268
Community Visitor
Community Visitor
hey,bro.Did you solve it?
Message 4 of 4

waleed.hany
Contributor
Contributor
Accepted solution

I could not find a way to solve it using the revit api.
So I had to use raycasting (ReferenceIntersector class in revit api) to work arround the issue as follows:
1- Get an element's origin,
2- raycast a ray from the origin in the view direction using ReferenceIntersector class
3- if the ray intersection returned any elements, I will assume that the element is not visible in the view (obscured) 

This work around worked well for me, not sure if there is a better approach.

Notes: I fiond ReferenceIntersector slow in performance, and it is recommended to open a new 3d view and set it as the current view before performing this operation, then when fineshed, close the 3d view and set the previous view to the document's current view
https://www.revitapidocs.com/2020/36f82b40-1065-2305-e260-18fc618e756f.htm

Hopefully this workaround is usefull