try:
user_active_view = uidoc.ActiveView
user_opened_views = uidoc.GetOpenUIViews()
views = [view for view in FilteredElementCollector(doc).WherePasses(ElementClassFilter(ViewPlan)) if view.IsValidObject and not view.IsTemplate and view.ViewType != ViewType.CeilingPlan]
for view in views:
uidoc.ActiveView = view
uidoc.ActiveView = user_active_view
user_opened_views_ids_set = set(ui_view.ViewId for ui_view in user_opened_views)
for ui_view in uidoc.GetOpenUIViews():
if ui_view.ViewId not in user_opened_views_ids_set:
ui_view.Close()
except Exception as exception:
print exception.message