I am running the "Convert Labels To Annotation" tool in ArcGIS Pro using the Python window. I need to save the output group layer to it's own lyrx file.
According to the tool documentation, it should be fairly simple: "when working in the Catalog pane, the Python window, or a stand-alone Python script, you can use the Save To Layer File tool to write the output group layer to a layer file." However, I am struggling to understand where the group layer actually is to then be able to save it.
I have following code:
for area in os.listdir(outfolder):
if area == "test":
# Find the aprx file in each plan
project = outfolder + "\\" + area + "\\" + area + ".aprx"
annoLyr = outfolder + "\\" + area + "\\" + area + "_Annos.lyrx"
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 on", 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,
conversion_scale=sc,
output_geodatabase=aprx.defaultGeodatabase,
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"
)
arcpy.management.SaveToLayerFile("Annotations", annoLyr, "RELATIVE", "CURRENT")
print("Labels have been converted to annotations.")
The SaveToLayerFile doesn't work because it cannot find the "Annotations" group layer (my intended output from line 32.
I also tried listing the layers in the map object but the group layer "Annotations" hasn't been added to the map, so I cannot export it via that route either.
Anyone know where the group layer from line 32 is being output, so I can retrieve it using arcpy?