[GIS] Handle annotation layers with arcpy

annotation;arcgis-10.1arcmaparcpy

I want to access annotation layers using arcpy (the purpose is to verify few text strings in text annotations). By annotation I mean draw tool annotations, not dynamic labels. These annotation layers are under a groups layer by the name of 'Default'.

The Esri documentation talks of draw annotation as being layers themselves :

There are essentially three categories of layers in a map document: feature layers, group layers, and raster layers. The isFeatureLayer, isGroupLayer, and isRasterLayer properties allow you to identify or isolate the majority of layer types but not all layer types. There are a few specialized layers and datasets that don't fall into one of these three categories: annotation subclasses, dimension features, network datasets, terrain datasets, topology datasets, and so on. In these cases you may need to test other properties to isolate a layer of interest before doing something to it.

One thing to be aware of is how ArcGIS handles draw annotations, two mean configurations are possible :

ArcGIS fully supports two types of annotation: geodatabase and map document

In my case, it's map document.


In light of all this documentation, it so appears that draw annotations are mere layers, thus a simple code such as this should be working :

mxd = arcpy.mapping.MapDocument("some\mxdpath\here")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")
lyr = arcpy.mapping.ListLayers(mxd,"current_annotation_layer",df) 

But the problem is the annotations do not seem obtainable via dataframe (which is weird considering each of my annotation layers is associated to a feature layer).


Is there any specific ArcPy class to access annotations (one comparable to IAnnotationFeature2 of ArcObject SDK)?

Best Answer

ArcPy does not expose all of ArcObjects. From what I can tell, this is one of the many interfaces that are not exposed in ArcPy. Only Page Layout elements are exposed in arcpy: ListLayoutElements (arcpy.mapping)

If you need to do this your only choice is ArcObjects. If you want to use Python, see How do I access ArcObjects from Python?

Otherwise you might want to look for or create an ArcGIS Idea about this (the only relevant existing idea I found was this one).

Related Question