t = Transaction(doc, __title__)
t.Start()
all_categories = doc.Settings.Categories
cats_annotation = [cat for cat in all_categories if cat.CategoryType == CategoryType.Annotation]
exclude = [BuiltInCategory.OST_SectionBox]
for cat in cats_annotation:
if cat.BuiltInCategory in exclude:
continue
view.SetCategoryHidden(cat.Id, True)
t.Commit()