def get_view_by_name(view_name):
"""Get Views by exact Name."""
views = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
for view in views:
if view.Name == view_name:
return view
raise("Couldn't find view by name: {}".format(view_name))
view_from = get_view_by_name('HG_UG 1_OK FFB')
view_to = get_view_by_name('HG_UG 1_OK FFB Copy 1')
filter_ids = view_from.GetOrderedFilters()
filters = [doc.GetElement(f_id) for f_id in filter_ids]
sel_filters = forms.SelectFromList.show(filters,
multiselect=True,
name_attr='Name',
button_name='Select View Filters')
if not sel_filters:
forms.alert("No View Filters were Selected.\n"
"Please Try Again.", exitscript=True)
with Transaction(doc, 'Copy ViewFilters') as t:
t.Start()
for view_filter in filters:
overrides = view_from.GetFilterOverrides(view_filter.Id)
view_to.SetFilterOverrides(view_filter.Id, overrides)
visibility = view_from.GetFilterVisibility(view_filter.Id)
enable = view_from.GetIsFilterEnabled(view_filter.Id)
view_to.SetFilterVisibility(view_filter.Id, visibility)
view_to.SetIsFilterEnabled(view_filter.Id, enable)
t.Commit()