View Filter Order

View Filter Order

colin_magner
Advocate Advocate
3,004 Views
11 Replies
Message 1 of 12

View Filter Order

colin_magner
Advocate
Advocate

I've written an addin that succesfully copies view filters and their overrides from one view template to another, however the filters end up in a different sequence.  Having created the view templates myself, I think that the filters are being copied in order that they were added to the view template, however I used the UI controls to move filters up/down to achieve the desired sequence.

 

Does anyone know if it's possible to match the filter sequence via the API?

 

Thanks.

0 Likes
3,005 Views
11 Replies
Replies (11)
Message 2 of 12

gopinath.taget
Alumni
Alumni

Hello,

 

I do not see any API that directly allows you to change the order of the filters. However, here is something your could try to do:

 

1) Get the collection of filters using the View.GetFilters method. The collection order is probably what you see in the UI.

2) Remove the filters from the view using View.RemoveFilter.

3) Use View.AddFilter to add filters in the order you want.

 

Not sure if it helps but worth a try.

 

Thanks

Gopinath 

0 Likes
Message 3 of 12

colin_magner
Advocate
Advocate

Thanks for the suggestion Gopinath, but I don't think it resolves the issue.  My code removes all filters from a view template, then adds filters from another template using .GetFilters and adding each in turn using .AddFilter. 

 

From what I can tell, the API adds the filters based on the order in which the filters themselves were defined, rather than their order in the view they're being copied from, or the order in which they were originally added to the view.

0 Likes
Message 4 of 12

Anonymous
Not applicable

Hello,

 

Can you please provide a snippet of code that shows how you copy the filters from the second template into the first?

 

Thanks

Gopinath

0 Likes
Message 5 of 12

colin_magner
Advocate
Advocate

Sure:

 

I've got two 'views' which I set to match the view template for the active view (TemplateActiveView) and the view template that I use to copy the settings from (TemplatePlan).

 

Autodesk.Revit.DB.View TemplateActiveView;

Autodesk.Revit.DB.View TemplatePlan;

 

Prior to copying the filters I clear the current filters from TemplateActiveView

 

           foreach (ElementId id in TemplateActiveView.GetFilters())

            {

                TemplateActiveView.RemoveFilter(id);

            }

 

I then copy the filters and apply their override settings, by iterating through each filter in the 'template', getting its overrides, adding it to the template of the active view, then I retrieve the filter from the active view (by iteration, couldn't find a cleaner way) and apply the overrides and visibility settings.

           

OverrideGraphicSettings TemplateOverrides = new OverrideGraphicSettings();

           

foreach (ElementId id in TemplatePlan.GetFilters())

            {

                TemplateOverrides = TemplatePlan.GetFilterOverrides(id);

                TemplateActiveView.AddFilter(id);

               

        foreach (ElementId newID in TemplateActiveView.GetFilters())

                {   

          if (m_doc.GetElement(newID).Name == m_doc.GetElement(id).Name)

                    {

                        TemplateActiveView.SetFilterOverrides(newID, TemplateOverrides);

                        TemplateActiveView.SetFilterVisibility(newID, TemplatePlan.GetFilterVisibility(id));   

            break;

                    }

                }

            }

0 Likes
Message 6 of 12

Anonymous
Not applicable

Well, your code seems fine. I have passed on your query to the engineering team. I will let you know what I learn. Thanks for your patience.

 

Best Regards

Gopinath

0 Likes
Message 7 of 12

colin_magner
Advocate
Advocate

No problem, thanks for your input.

0 Likes
Message 8 of 12

gopinath.taget
Alumni
Alumni

Hi Colin,

 

Thanks for your patience but I do not yet have any useful info. I will get back to you as soon as I have something.

 

Thanks

Gopinath

0 Likes
Message 9 of 12

Anonymous
Not applicable

Hi Colin,

 

Apologies for the delay in getting back to you. I don't have a resolution for the issue so I logged a change request with the engineering team and sent you the details separately.

 

My engineering colleague had this to say:

 

*--------------

It turns out that the order of filters is saved, but is not reflected in what you get out from GetFilters().   

 

There is no way to read the filter order with the current API.  

 

There IS a way to set the filter order – remove all filters with RemoveFilter(), then use AddFilter() in the desired order.  You’ll probably have to save and then reapply the associated overrides and visibility for each filter (SetFilterOverrides(), SetFilterVisibility()).

*---------------

 

Sorry for not being more helpful.

 

Best Regards

Gopinath

0 Likes
Message 10 of 12

Ning_Zhou
Advocate
Advocate
having exact the same issue, even cannot manually change its order unless delete and recreate
0 Likes
Message 11 of 12

Anonymous
Not applicable

Has this been fixed in the new API? I am still having this problem 😞

0 Likes
Message 12 of 12

jeremytammik
Autodesk
Autodesk

The wishlist item CF-1486 [Need API to order the view filters on a view] that was raised based on the original thread ended up being closed again, since the original requester said it was of little importance to him.

I suggest you do two things:

 

  • Submit this as an entry in the Revit Idea Station and ensure it gets many votes. Maybe it is already in there?
  • Submit a business case explaining the importance of this wish for you, your customers, the community, Autodesk, your revenue, etc. to underline its importance.


I hope this helps.

Cheers,

Jeremy



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

0 Likes