AnsweredAssumed Answered

How can we change the label to Annotation for point layer through Arcpy(Python)?

Question asked by manjarigoyal on Oct 12, 2016
Latest reply on Oct 12, 2016 by BWhite-esristaff

I am trying to convert the label for a point layer to annotation. Below is my script and the error I am getting.


import arcpy
from arcpy import env
import arcpy.mapping


# Set environment settings
env.workspace = "C:\Users\Documents"
arcpy.env.overwriteOutput = True


#define projection
Prjfile = r"C:\\Users\\Documents\\WGS1984.prj"
spRef = arcpy.SpatialReference(Prjfile)


#Local Variables

FC7 = r"C:\Users\Documents\South.gdb\Search_Ring"

mxd = arcpy.mapping.MapDocument(r"C:\Users\Documents\Demo_South.mxd")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

## Convert Feature class to feature layer
arcpy.MakeFeatureLayer_management(FC7, r"C:\Users\Documents\Search_Ring.lyr")

layer7 = arcpy.mapping.Layer(r"C:\Users\Documents\Search_Ring.lyr")
Sym_layer7 = r"C:\Users\Documents\Search Ring.lyr"

## Apply symbology and add layer to MXD
arcpy.ApplySymbologyFromLayer_management (layer7, Sym_layer7)
arcpy.mapping.AddLayer(df, layer7, "TOP")
lyr7 = arcpy.mapping.ListLayers(mxd, "", df)[0]

## Add the labels and its format
lyr7.labelClasses[0].expression = '"{}" + [Candidate_Code] + "{}"'.format("<CLR blue='255'><FNT size = '9'><BOL>", "</BOL></FNT></CLR>")
lyr7.showLabels = True

## Convert label to Annotation
arcpy.ConvertLabelsToAnnotation_defense (mxd, "")

## Add Layer Properties
lyr7.visible = False = "Search_Ring"
lyr7.maxScale = 0;
lyr7.minScale = 5000000;
lyr7.transparency = 25;


## Save the mxd

del mxd,df






Any help is appreciated.