Filters in view template

Filters in view template

Anonymous
Not applicable
2,206 Views
4 Replies
Message 1 of 5

Filters in view template

Anonymous
Not applicable

I'm trying to get all fiters in view template, and the code below works for some projects, but not all. 

exception: the view type does not support visiblity/graphics overrides

 

what i have found is,  view.GetFilters() method will not return the view template in which there's no filters. for instance,  i have template 1,2,3, and  only the 3 has no filters, when i export to excel , there are only template 1 and 2. 

but when all my templates have no filters in them, it returns the exception ---the view type does not support visiblity/graphics overrides

 

is there any way to check if view template contains filters or not first ? 

or maybe better way to handle this exception?   Thx 

            foreach (View view in ViewTemp)
            {

                string _Id, _Name, _ClassName, _ViewtempName;
                
                if (view.IsTemplate)
                {
                            ICollection<ElementId> filterIds = view.GetFilters();
                            foreach (ElementId id in filterIds)
                            {
                                Element filter = doc.GetElement(id);
                                _Id = filter.Id.ToString();
                                _Name = filter.Name;
                                _ClassName = filter.GetType().Name;
                                _ViewtempName = view.Name;
                                object[] FilterData = { _Id, _Name, _ClassName, _ViewtempName };
                                FilterDataList.Add(FilterData);
                            }
                }
            }

 

0 Likes
Accepted solutions (1)
2,207 Views
4 Replies
Replies (4)
Message 2 of 5

TheRealChrisHildebran
Advocate
Advocate

Just an observation while using the the Revit Lookup tool.

 

It appears that if a View Template is not associated with a view the .GetFilters() method returns no Filters. As soon i associated the View Template with a view the .GetFilters() method works.

 

This behavior seems odd. Again, I havent tested this in code. Only using Revit Lookup.

 

As far as the exporting goes im not sure.

0 Likes
Message 3 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

You can use View.AreGraphicsOverridesAllowed 

Likely in one of your projects you have a view that doesn't allow this but it passes your other criteria (depends how you generated 'ViewTemp' collection).

0 Likes
Message 4 of 5

Anonymous
Not applicable

Thanks for your reply. it works even when some of vues don't have view template, it also works even some view templates have no filters in it. but it throws an exception when all view templates have no filters....

i know it's weird when all view templates have no filters..but this is not something i can decide.

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

O Gee, that's where the problem is ... and i thought it was my filters problem. life savor. Thanks. 

0 Likes