I am trying to use a label expression with ArcGIS formatting tags to create a shadow on my text. I have done everything I need except assigning a value of 1 to X offset, and a value of -1 to Y offset.

Below is my code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
updateLayer = arcpy.mapping.ListLayers(mxd, "OCParcelsAPN selection", df) [0]
sourceLayer = arcpy.mapping.Layer(r"L:\GISLibrary\Scripts\Python\ReferenceLayers\OCParcels_selection.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)

del sourceLayer

mxd = arcpy.mapping.MapDocument(r"CURRENT")
layer = arcpy.mapping.ListLayers(mxd) [0]

if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.className = "ASSESSMENT"
        lblclass.expression = '"<FNT name=""Futura Md BT"" size=""6""> <CLR red=""255"" green=""255"" blue=""0"">" & [ASSESSMENT] & "</CLR> </FNT>"'
        lblclass.showClassLabels = True

        layer.showLabels = True


enter image description here


As @PolyGeo stated, it is an ArcPy limitation.

The workaround is to configure these properties in a .lyr file on disk (once-off using ArcMap) and then use that layer file in the arcpy script.

In the case of your script, you are already using a layer file on disk, so this simply means updating these properties using ArcMap (once only) in the existing file you already reference here:

sourceLayer = arcpy.mapping.Layer(r"L:\GISLibrary\Scripts\Python\Reference         Layers\OCParcels_selection.lyr")

The way you are changing font, color and size is by using Text Formatting tags:

ArcGIS text formatting tags let you modify the formatting for a portion of text. This lets you create mixed-format text where, for example, one word in a sentence is underlined. Text formatting tags can be used almost anywhere text is placed on or around the map in ArcMap.

However, modifying shadow is not available within text formatting tags so I think you are up against an ArcPy limitation. You could submit an ArcGIS Idea for this, but if you do, I recommend targeting ArcGIS Pro's arcpy.mp rather than the arcpy.mapping module of the ArcGIS 10.x architecture.

I suspect that in ArcGIS Pro this functionality may now be available to you from ArcPy by using Python CIM Access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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