0

I am trying to create a script that exports labels to annotation using the tool in ArcGIS Pro 2.4. I have created the contour layer, converted it to Layer and that works fine, but I am stuck on the creation of labels below is my script for the portion I am stuck on , this generates a label fine however the label is the ID column rather than the Contour column and I cannot work how to specify an expression. I have tried the help and suggested code (https://pro.arcgis.com/en/pro-app/arcpy/mapping/labelclass-class.htm) but this has not been any use it seems to suggest my layer does not support "SHOWLABEL" yet it generates fine using my code.

for lyr in aprxmap.listLayers():
    if lyr.supports("SHOWLABELS"):
        lyr.showLabels = True
        lyr.expression = "[Contour]"
        lyr.SQLQuery = "Type_ = 'Contour'"
        print("Convert Labels \n")
        arcpy.cartography.ConvertLabelsToAnnotation(aprxmap,
                                                    1000,
                                                    r"tester.gdb",
                                                    "try",
                                                    "DEFAULT",
                                                    "GENERATE_UNPLACED",
                                                    "NO_REQUIRE_ID",
                                                    "STANDARD",
                                                    "AUTO_CREATE",
                                                    "SHAPE_UPDATE",
                                                    "GroupAnno2",
                                                    "SINGLE_LAYER",
                                                    lyr,
                                                    "FEATURE_CLASS_PER_FEATURE_LAYER",
                                                    "NO_MERGE_LABEL_CLASS")`

1 Answer 1

1

If you follow your own link and examine the second code sample, you will note they obtain the label Class from the layer and they are setting the properties of the label class. In your code you are setting properties of a layer object, not it's label class. I'm surprised it even runs as expression and SQLQuery are not properties/methods on a layer object?

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