Find user-defined view filters that affect certain elements

Find user-defined view filters that affect certain elements

tebogo.schultzH5FH3
Contributor Contributor
925 Views
3 Replies
Message 1 of 4

Find user-defined view filters that affect certain elements

tebogo.schultzH5FH3
Contributor
Contributor

Back with another fun one.  I need to seek out filters defined on a view (or template) that may affect the visibility of important elements that are being added to a sheet by my add-in.

 

Can anyone help me fill in the missing method?

 

        static void checkAndRemoveFilters(Document doc, View view, ElementId mustBeVisible)
        {
            if(view.GetFilters().Count() > 0)
            {
                foreach(ElementId id in view.GetFilters())
                {
                    FilterElement filter = doc.GetElement(id) as FilterElement;

                    //????
                    //if(filter.wouldHide(mustBeVisible)) 
                    //{
                    //...
                    //}
                }
            }
        }
0 Likes
926 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

It might help if you describe some examples of tricky criteria that might cause an important element to be invisible.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

tebogo.schultzH5FH3
Contributor
Contributor

That's what I don't know?  But for now, I'm talking about just the filters.

0 Likes
Message 4 of 4

mhannonQ65N2
Collaborator
Collaborator

You're going to have to switch on/check the type of the FilterElement to determine how to check this.

 

For ParameterFilterElements, you'll need to call GetElementFilter to get an ElementFilter, then call PassesFilter on the ElementFilter with the element(s) of interest.

 

For SelectionFilterElements, you can call Contains with the Id(s) of the element(s) of interest.

 

Personally, I would put the code for determining if a FilterElement affects a given Element in an extension method or local function.

0 Likes