Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

View Filter Order

11 REPLIES 11
Reply
Message 1 of 12
colin.magner
2168 Views, 11 Replies

View Filter Order

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.

11 REPLIES 11
Message 2 of 12

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 

Message 3 of 12

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.

Message 4 of 12
SGPViewer
in reply to: colin.magner

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

Message 5 of 12
colin.magner
in reply to: SGPViewer

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;

                    }

                }

            }

Message 6 of 12
SGPViewer
in reply to: colin.magner

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

Message 7 of 12
colin.magner
in reply to: SGPViewer

No problem, thanks for your input.

Message 8 of 12

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

Message 9 of 12
SGPViewer
in reply to: colin.magner

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

Message 10 of 12
Ning_Zhou
in reply to: SGPViewer

having exact the same issue, even cannot manually change its order unless delete and recreate
Message 11 of 12
lankitjd
in reply to: SGPViewer

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

Message 12 of 12
jeremytammik
in reply to: lankitjd

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community