Programmatically hide elements in a View

Programmatically hide elements in a View

joaofmoco
Advocate Advocate
974 Views
2 Replies
Message 1 of 3

Programmatically hide elements in a View

joaofmoco
Advocate
Advocate

Hello,

 

There's a question that has been going through my mind:

Is there a way to programmatically hide elements in a View using the Revit API?

 

For example:

I have created a Structural Plan and the schematic looks like this:

imagem_2022-04-20_092824189.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I want to hide the Project Base Point and the Survey Point, as well as the Elevation Views for North, South, East and West. I'd also like to hide the green and red arrows (I don't think that's possible, however, according to some research done by me).

 

What code would I need to write to achieve that?

 

Any feedback is appreciated 🙂

0 Likes
Accepted solutions (1)
975 Views
2 Replies
Replies (2)
Message 2 of 3

longt61
Advocate
Advocate
Accepted solution

You may want to take a look at the View.HideElements() method as follow:

View view = Get_your_view();
List<ElementId> elemIdToHide = Get_your_element_ids_to_hide_in_view();
view.HideElements(elemIdToHide);

 

Here is the complete code to hide survey point and project base point in active view:

 private void HideProjectBasePoint(UIDocument uidoc)
        {
            View view = uidoc.ActiveGraphicalView;
            if (view != null)
            {
                // get id of survey point and project base point
                List<ElementId> basePointIds = new FilteredElementCollector(uidoc.Document, view.Id)
                                                .WhereElementIsNotElementType()
                                                .OfClass(typeof(BasePoint))
                                                .ToElementIds()
                                                .ToList();
                if (basePointIds?.Count > 0)
                    view.HideElements(basePointIds);

            }
        }
0 Likes
Message 3 of 3

joaofmoco
Advocate
Advocate

Hello longt61 and thank you for your reply,

 

I've adapted your code to my needs and it works perfectly.

Thank you so much for the explanation and the code!

0 Likes