Create/Update SelectionFilterElement

import clr
clr.AddReference('System')
from System.Collections.Generic import List

#1 Get All Selection Filters
all_sel_filters  = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
dict_sel_filters = {f.Name: f for f in all_sel_filters}

# Get Elements For Selection Filter
element_ids = FilteredElementCollector(doc).OfClass(Wall).ToElementIds()
element_ids = List[ElementId](element_ids) 

t = Transaction(doc, 'Create Sel Filter')
t.Start()


# Selection Filter Name
new_filter_name = 'py_Filter'

# Create new if doesn't exist
if new_filter_name not in dict_sel_filters:
    new_fil = SelectionFilterElement.Create(doc, new_filter_name)
    new_fil.AddSet(element_ids)


# Update if already exists
else:
    existing_fil = dict_sel_filters[new_filter_name]
    existing_fil.AddSet(element_ids)


t.Commit()

⌨️ Happy Coding!
Erik Frits