Python Help needed - Hide Grids from links in all views

Am not a python user yet, can anyone help me to edit the below code from “Quasar package” to run in all views at once rather than running in only active view

# dynamo version - 1.3.2
# author - min.naung

import clr
import System

from System.Collections.Generic import List
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# document manager
doc = DocumentManager.Instance.CurrentDBDocument
# start transaction

# active view
active_view = doc.ActiveView
# filter name "can name anything"
ifilter = "LinkLevelGrid_QuasarPackage"
found = False

# input[0] boolean
hide = False if IN[0] else True

# collect all filter elements
allFilters = FilteredElementCollector(doc).OfClass(FilterElement).ToElements()

# get filters from current view
viewFilters = active_view.GetFilters();
# collect filters' names
viewFiltersName = [doc.GetElement(i).Name.ToString() for i in viewFilters]

# loop each filter
for fter in allFilters:
# filter already have in doc but not in current view
if ifilter == fter.Name.ToString() and ifilter not in viewFiltersName:
# add filter

# set filter visibility
active_view.SetFilterVisibility(fter.Id, hide);
found = True
# filter already have in doc and current view
if ifilter == fter.Name.ToString() and ifilter in viewFiltersName:
# set filter visibility
active_view.SetFilterVisibility(fter.Id, hide);
found = True

# if filter not found in doc
if not found:
# all grids in doc
grids = FilteredElementCollector(doc).OfClass(Grid).ToElements()
# all levels in doc
levels = FilteredElementCollector(doc).OfClass(Level).ToElements()
# collect category id from grid and level
CateIds = List[ElementId]([grids[0].Category.Id,levels[0].Category.Id])

# type ids from grids
gridTypeIds = set([i.GetTypeId() for i in grids])
# type ids from levels
levelTypeIds = set([i.GetTypeId() for i in levels])

# get grid type element
type_elems = [doc.GetElement(i) for i in gridTypeIds]
# get level type element
type_elems.extend([doc.GetElement(l) for l in levelTypeIds])

# loop type elements
for elem in type_elems:
# if "_quasar" not include in type name
if not "_quasar" in elem.LookupParameter("Type Name").AsString():
# add "_quasar" in type name
elem.Name = elem.LookupParameter("Type Name").AsString() + "_quasar";
# get type names
type_names = [i.LookupParameter("Type Name").AsString() for i in type_elems]
# type name parameter id
paramId = type_elems[0].LookupParameter("Type Name").Id
# create a "not ends with" filter rule
notendswith = ParameterFilterRuleFactory.CreateNotEndsWithRule(paramId,"_quasar",False)
# create parameter filter element
paramFilterElem = ParameterFilterElement.Create(doc, ifilter,CateIds,[notendswith])
# set filter overrides (same with add filter to current)
active_view.SetFilterOverrides(paramFilterElem.Id, OverrideGraphicSettings())
# set filter visibility
active_view.SetFilterVisibility(paramFilterElem.Id, hide)

# transaction done

# output

Hi, do not know “Quasar” or “Python” but would it not help setting up your “view template” after loading this into a view and then assigning the “view template” to all your views?

I think the other solution should be around this - maybe change it from “doc. ActiveView” to “doc.“AllView””

We use a filter for this
We use the Grid TypeName parameter to filter

@mohamed.mostafaDQCGU, get it from here;