Convert Labels To Annotation not working via arcpy without opening up the relevant aprx files

443
1
Jump to solution
10-18-2023 11:50 AM
Labels (1)
ASw93
by
Occasional Contributor

I have a list of aprx files in a directory and I am looking to use arcpy to convert the labels within each one to annotations. However, when I run this, it doesn't seem to accept my parameter for 'input_map':

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000735: Input Map: Value is required
Failed to execute (ConvertLabelsToAnnotation).

However, line 13 correctly prints the name of the map within my aprx files so I know that bit of the code is working correctly.

If I open up one of the aprx files, the code works fine for that file and converts the labels, but not for other aprx files. It's as if this tool cannot be run without actually opening up each aprx - is this the case? The second example in the documentation suggests it can be run outside.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/cartography/convert-labels-to-annotation.htm

If so, how do I automate this some other way?

 

for area in os.listdir(outfolder):
    
    # Find the aprx file in each plan
    project = outfolder + "\\" + area + "\\" + area + ".aprx"
    print(project)
            
    print("Opening ArcGIS Project for", area)
    aprx = arcpy.mp.ArcGISProject(project)

    for map in aprx.listMaps():
        if "_10" in map.name:
            
            print("Running", map.name)
            for sc in scales:

                print("Converting all labels to annotation at scale {}".format(sc))

                #Convert all labels in entire map to Annotation
                arcpy.cartography.ConvertLabelsToAnnotation(
                input_map=map.name,
                conversion_scale=sc, #set to different scales
                output_geodatabase=aprx.defaultGeodatabase, #this will be the Data.gdb assigned to the project
                anno_suffix="Anno",
                extent="DEFAULT",
                generate_unplaced="GENERATE_UNPLACED",
                require_symbol_id="NO_REQUIRE_ID",
                feature_linked="STANDARD",
                auto_create="AUTO_CREATE",
                update_on_shape_change="SHAPE_UPDATE",
                output_group_layer="Annotations",
                which_layers="ALL_LAYERS",
                single_layer=None,
                multiple_feature_classes="FEATURE_CLASS_PER_FEATURE_LAYER",
                merge_label_classes="NO_MERGE_LABEL_CLASS"
                )

 

 

 

 
0 Kudos
1 Solution

Accepted Solutions
ASw93
by
Occasional Contributor

The solution was simple. Corrected the input_map parameter to the following:

input_map = map

View solution in original post

0 Kudos
1 Reply
ASw93
by
Occasional Contributor

The solution was simple. Corrected the input_map parameter to the following:

input_map = map
0 Kudos