AnsweredAssumed Answered

Error creating anotation

Question asked by recurvata on Jun 21, 2018

I'm trying to create annotation in arcpy for four line feature classes. The code below generates annotation, but instead of a separate annotation class for each layer, it creates 4 copies of the first layer. I'm thinking the problem is in the loop somewhere, but nothing I try seems to fix it. When I print the layer name in the loop, it prints the correct name.

Any clues? Thanks.


lyrs = arcpy.mapping.ListLayers(mxd)
    for mapLayer in lyrs:
        if mapLayer.supports("LABELCLASSES"):
            print("\t5b. Setting diameter label properties for {}...".format(
            mapLayer.showLabels = True
            for lblClass in mapLayer.labelClasses:
                lblClass.className = 'Diameter_{}'.format(
                lblClass.expression = '"Diameter: " & [DIAMETER] & """"'
                if == 'WATER_MAIN':
                     lblClass.expression = '"Diameter: " & [DIAMETER] & """" & "  Plan: " & [PLANNUMBER]'
            mapLayer.showLabels = True

            print("\t5c. Creating diameter annotation for {}...".format(
            arcpy.TiledLabelsToAnnotation_cartography(map_document = "path_to_mxd",
                                                  data_frame = "OUPS",
                                                  polygon_index_layer = "anno_extent",
                                                  out_geodatabase = interim_gdb,
                                                  out_layer = 'GroupAnno',
                                                  anno_suffix = '_Anno_diam_',
                                                  generate_unplaced_annotation = 'GENERATE_UNPLACED_ANNOTATION')


In Arc Catalog...

Snip of annotation in ArcCatalog


In interpreter window

    5b. Setting diameter label properties for WATER_SERVICE...
    5c. Creating diameter annotation for WATER_SERVICE...
    5b. Setting diameter label properties for WATER_MAIN...
    5c. Creating diameter annotation for WATER_MAIN...
    5b. Setting diameter label properties for STORM_MAIN...
    5c. Creating diameter annotation for STORM_MAIN...
    5b. Setting diameter label properties for SANITARY_MAIN...
    5c. Creating diameter annotation for SANITARY_MAIN...