Set new Selection in Revit UI

Note that there are 2 ways of preparing List[ElementId](), you only need to choose either A or B!

It also doesn't require any Transactions!

#🔷 SetElementIds (P.S. modify ElementId to yours!)

# Prepare List[ElementId] - A
python_list = [ElementId(347164),
               ElementId(347244),
               ElementId(347326),
               ElementId(347399)]
new_selection = List[ElementId](python_list)

# Prepare List[ElementId] - B
new_selection = List[ElementId]()
new_selection.Add(ElementId(347164))
new_selection.Add(ElementId(347244))
new_selection.Add(ElementId(347326))
new_selection.Add(ElementId(347399))

#🎯 Set New Selection
selection.SetElementIds(new_selection)

⌨️ Happy Coding!
Erik Frits