Get All Annotation Elements in Document

Hi,

I’m trying to get all annotation elements in my model but something is wrong.
My knowledge of the revit API is limited. Could someone tell me what is wrong with my code?

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument


allElements = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()

annotationElements = []

for element in allElements:
	if element.Category.CategoryType == CategoryType.Annotation:
	 annotationElements.append(element)

OUT = annotationElements

I get this error…
*Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. *
Traceback (most recent call last):

  • File “”, line 18, in *
    AttributeError: ‘NoneType’ object has no attribute ‘CategoryType’

That error says that one of your elements is null. I would highly suggest filtering your elements some more. Since you don’t appear to need types, I’d suggest specifically filtering for FamilyInstances or annotation categories. This will be much better than going through everything in your whole project.