10

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).


Any specific arcpy class to access annotations (one comparable to IAnnotationFeature2 of ArcObject SDK)? Any workaround ?

Thanks !

  • Did you manage to modify your map document annotation group via comptypes and ArcObjects? Any pointers for further info? Many thanks!! – Hélène Sep 1 '15 at 12:57
3

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).

  • Hi, I was sort of expecting this answer, but thanks and +1 for the links, this might help. – Akheloes Mar 13 '14 at 19:09
  • @Akheloes Did you manage to modify your map document annotation group via comptypes and ArcObjects? – Hélène Aug 27 '15 at 13:47
0

I'm adding a response in case others stumble upon this. Annotations ARE accessible via arcpy and can be treated as layers. The code didn't work because it's missing an index, NOT because annotations aren't accessible. These functions return a list every time, so even if you are using a wildcard (in this case "Layers" and "current_annotation_layer"), you still need to specify the index to retrieve it and assign it to an object (df & lyr respectively).

Code should be:

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListDataFrames(mxd, "current_annotation_layer", df)[0]

Here's an example I used arcpy to access my annotation layer. For my map, I wanted the annotation to be moved below a mask with 20% transparency if it was outside my area of interest.

my_annotation_lyr = arcpy.mapping.Layer("Long_ProjectsAnno")
reference_lyr = arcpy.mapping.Layer("counties_mask")
arcpy.mapping.MoveLayer(df, reference_lyr, my_annotation_lyr, "AFTER")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.