Annotation classes not visible after adding an annotation layer

2812
3
Jump to solution
02-22-2013 08:27 AM
YonghaHwang
New Contributor II
I have an annotation feature. I can see its annotation classes when I drag-and-drop the feature from ArcCatalog to ArcMap. But I can't see the annotation classes when I add the annotation feature using ArcPy. I can't even see Annotation tab in the layer properties dialog. The layer doesn't look like Annotation at all (it looks like simple geometry feature), but Layer Properties>Source>Feature Type says the layer is "Annotation".

How can I add the annotation layer properly in Arcpy?
My environment: ArcGIS 10.1 / Windows XP 32 bit

My codes are:

import arcpy  my_mxd = arcpy.mapping.MapDocument("C:/PATH/TO/blank.mxd") df = arcpy.mapping.ListDataFrames(my_mxd)[0] anno_path = "C:/PATH/TO/some.gdb/BuildingAnno" anno_layer= arcpy.mapping.Layer(anno_path) arcpy.mapping.AddLayer(df,anno_layer) my_mxd.saveACopy("C:/PATH/TO/saved.mxd")


[ATTACH=CONFIG]22088[/ATTACH]
The first layer is an annotation layer added by ArcPy and the second one is added using drag-and-drop from ArcCatalog.

Thanks,
Yongha
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
YonghaHwang
New Contributor II
I found a solution. If you are going to add an annotation layer using ArcPy, you should not just add the annotation layer directly with mapping.AddLayer. Instead, you have to generate a layer using MakeFeatureLayer_management and then add the layer using mapping.AddLayer.

import arcpy  my_mxd = arcpy.mapping.MapDocument("C:/PATH/TO/blank.mxd") df = arcpy.mapping.ListDataFrames(my_mxd)[0] anno_path = "C:/PATH/TO/some.gdb/BuildingAnno"  temp_layer = "temp_anno" arcpy.MakeFeatureLayer_management(anno_path,temp_layer) anno_layer= arcpy.mapping.Layer(temp_layer) arcpy.mapping.AddLayer(df,anno_layer) my_mxd.saveACopy("C:/PATH/TO/saved.mxd")

View solution in original post

0 Kudos
3 Replies
YonghaHwang
New Contributor II
I think ArcPy adds an annotation layer as feature layer. After the annotation layer is added to the mxd file, I checked isFeature property, it says the annotation layer is a feature layer (True), which should be False if the annotation layer is properly added as an annotation type layer. I think this should be fixed.
0 Kudos
YonghaHwang
New Contributor II
I found a solution. If you are going to add an annotation layer using ArcPy, you should not just add the annotation layer directly with mapping.AddLayer. Instead, you have to generate a layer using MakeFeatureLayer_management and then add the layer using mapping.AddLayer.

import arcpy  my_mxd = arcpy.mapping.MapDocument("C:/PATH/TO/blank.mxd") df = arcpy.mapping.ListDataFrames(my_mxd)[0] anno_path = "C:/PATH/TO/some.gdb/BuildingAnno"  temp_layer = "temp_anno" arcpy.MakeFeatureLayer_management(anno_path,temp_layer) anno_layer= arcpy.mapping.Layer(temp_layer) arcpy.mapping.AddLayer(df,anno_layer) my_mxd.saveACopy("C:/PATH/TO/saved.mxd")
0 Kudos
SchoppMatthieu
New Contributor III
Well done, thank you
0 Kudos