Select to view content in your preferred language

Adding annotation feature class with Python script

08-09-2018 08:09 AM
New Contributor II

I've created annotation feature classes from Microstation DGN files and I need to add those to a series of mxd's using arcpy. I've been able to do that, but the layers are added as polygon features not as annotation features. I've dug around and found this solutionAnnotation classes not visible after adding an annotation layer , but it doesn't work for me. The feature class still adds as a polygon layer. Has anyone else run into this? Below is the relevant code. 

for df in arcpy.mapping.ListDataFrames(mxd):
            if == "Layers":
                featclasses = arcpy.ListFeatureClasses("","",County_Nam)
                print featclasses
                for fc in featclasses:
                    print fc
                    addLayer = arcpy.mapping.Layer(fc)
                    reflayer = arcpy.mapping.ListLayers(mxd,"Private",df)[0]
                    if fc == County_Nam + "_Anno_Ins":
                        print fc
                        temp = County_Nam + "_Anno_Ins"
                        annoLayer = arcpy.mapping.Layer(temp)
                        arcpy.mapping.AddLayer(df, annoLayer, "BOTTOM")
0 Kudos
4 Replies
MVP Emeritus

That code... listed below... loads from disk

# ---- code from that post
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"
anno_layer= arcpy.mapping.Layer(temp_layer)

Do they load without issue if you do it manually?

New Contributor II

It does load properly when done manually. Seeing your repost of that code made me think to try to load a single feature class into an empty mxd, which worked. It took a few hours, but I finally figured out the problem had to do with the fact that I was trying to create the layer in the mxd to have the same name as the feature class in the gdb. Each feature class is named <some county>_Anno_Ins and when I changed this line in my script:

temp = County_Nam + "_Anno_Ins"‍


temp = County_Nam + "_DPatterson"‍

they were added to the mxd's properly as annotation. So problem solved. Thanks for the help.  

0 Kudos
MVP Emeritus

ahhh immortalized as an annotation

0 Kudos
New Contributor II

I'm sure it's not the first time.

0 Kudos