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.
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
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.
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
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;
}
}
}
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
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
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
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:
I hope this helps.
Cheers,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.