<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I change label style using ArcPy? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622870#M74363</link>
    <description>&lt;P&gt;Thank you &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;so much. I have applied your script and solved the labeling properties issue. I can change the font, color, and size of the labels using ArcPy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Get layer
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
lay = mp.listLayers("Ottawa_Census")[0]

# Enable labeling and turn off old label classes
lay.showLabels = True
for lc_old in lay.listLabelClasses():
    lc_old.visible = False
print('Old labels turned off')

# Create new label class
lay.createLabelClass(name='Label - Python',
                     expression='[DACODE]',
                     sql_query="POP_2016 &amp;gt;= 1000",
                     labelclass_language='Python')
print('New label class created')

# Placed after creating the new label class
laycim = lay.getDefinition("V3")

# Change the label style
for lc in laycim.labelClasses:
    if lc.name == 'Label - Python':  
        sym = lc.textSymbol.symbol
        sym.fontFamilyName = "Cambria"
        sym.fontStyleName = "Bold"
        sym.height = 8

        # Set the fill color
        fill = sym.symbol.symbolLayers[0]
        fill.color.values = [255, 0, 0, 255]  # red

        # Set the outline color and width
        outline = arcpy.cim.CIMSolidStroke()
        outline.color = [0, 100, 255, 255]  # blue
        outline.width = 1.5

        # Apply the new style
        sym.symbol.symbolLayers = [fill, outline]

# Apply the new defintion
lay.setDefinition(laycim)
print('Label class style updated and applied') &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 20:58:39 GMT</pubDate>
    <dc:creator>brusselsboy</dc:creator>
    <dc:date>2025-06-11T20:58:39Z</dc:date>
    <item>
      <title>How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622714#M74343</link>
      <description>&lt;P&gt;Hello everyone, I have created a label class to display labels for my feature layer.&lt;/P&gt;&lt;P&gt;However, the default label style is not ideal, and I want to customize the &lt;U&gt;&lt;STRONG&gt;font, size, color,&lt;/STRONG&gt; &lt;/U&gt;and other properties.&lt;/P&gt;&lt;P&gt;I noticed that &lt;STRONG&gt;the LabelClass object does not have a symbol attribute&lt;/STRONG&gt;.&amp;nbsp;&lt;A title="Label Class" href="https://pro.arcgis.com/en/pro-app/3.4/arcpy/mapping/labelclass-class.htm" target="_self"&gt;https://pro.arcgis.com/en/pro-app/3.4/arcpy/mapping/labelclass-class.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone advise how I can achieve this using &lt;STRONG&gt;ArcPy (ArcGIS Pro 3.4)&lt;/STRONG&gt;? I have searched various platforms but haven’t found a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Enable layer labels but toggle off all existing label classes
layer.showLabels = True   
for lc_old in layer.listLabelClasses():   
    lc_old.visible = False

# Create a new Label class and toggle it on     
lc_new = layer.createLabelClass(name = 'School Name - Python',
                         expression = '[NAME]',
                         labelclass_language = 'Python')

lc_new.visible = True            &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:03:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622714#M74343</guid>
      <dc:creator>brusselsboy</dc:creator>
      <dc:date>2025-06-11T17:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622721#M74344</link>
      <description>&lt;P&gt;I think it's as simple as running an `aprx.save()` after you finish.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Enable layer labels but toggle off all existing label classes
aprx = arcpy.mp.ArcGISProject("CURRENT")
layer.showLabels = True   
for lc_old in layer.listLabelClasses():   
    lc_old.visible = False

# Create a new Label class and toggle it on     
lc_new = layer.createLabelClass(name = 'School Name - Python',
                         expression = '[NAME]',
                         labelclass_language = 'Python')

lc_new.visible = True
aprx.save()&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:53:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622721#M74344</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T16:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622725#M74345</link>
      <description>&lt;P&gt;Look into CIM, but beware it suuuuuucks.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm" target="_blank"&gt;Python CIM access—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMVectorLayers.md" target="_blank"&gt;cim-spec/docs/v3/CIMVectorLayers.md at 809fb365d8d204d1fbdc51b3fab5bd17d88de2d1 · Esri/cim-spec · GitHub&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:54:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622725#M74345</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-06-11T16:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622729#M74346</link>
      <description>&lt;P&gt;Simply adding &lt;EM&gt;aprx.save()&lt;/EM&gt; doesn't help. I want to change the font, size, color of labels.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:04:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622729#M74346</guid>
      <dc:creator>brusselsboy</dc:creator>
      <dc:date>2025-06-11T17:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622761#M74348</link>
      <description>&lt;P&gt;Ah, in that case Alfred is correct. You'll have to do CIM editing. The Python API is awful, but you can do it. Here's a little starter with a re-implemented LabelClass CIM def with proper type hinting:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.cim import CIMSymbolReference
from arcpy.cim.CIMLabelPlacement import (
    CIMLabelClass,
    CIMMaplexGeneralPlacementProperties,
    CIMStandardLabelPlacementProperties,
)
from arcpy.cim import (
    LabelExpressionEngine,
    FeaturesToLabel,
)

class CIMLabelClass():
    """
      Represents a label class which describes how to generate a set 
      of text labels from a group of features in a feature layer.
    """
    def __init__(self, *args, **Kwargs):
        self.expressionTitle: str = ''
        self.expression: str = ''
        self.expressionEngine: LabelExpressionEngine = LabelExpressionEngine.VBScript
        self.featuresToLabel: FeaturesToLabel = FeaturesToLabel.AllVisibleFeatures
        self.maplexLabelPlacementProperties: CIMMaplexGeneralPlacementProperties = CIMMaplexGeneralPlacementProperties()
        self.maximumScale: float = 0.0
        self.minimumScale: float = 0.0
        self.name: str = ''
        self.priority: int = -1
        self.standardLabelPlacementProperties: CIMStandardLabelPlacementProperties = CIMStandardLabelPlacementProperties()
        self.textSymbol: CIMSymbolReference = CIMSymbolReference()
        self.useCodedValue: bool = True
        self.whereClause: str = ''
        self.visibility: bool = False
        self.iD: int = -1

aprx = arcpy.mp.ArcGISProject(r'path/to/project')
_map = [m for m in aprx.listMaps() if m.name == 'Map Name'][0]
lay = [l for l in _map.listLayers() if l.name == 'Layer Name'][0]
label = lay.listLabelClasses()[0]
label_def: CIMLabelClass = label.getDefinition('V3')

label_def.expressionEngine = LabelExpressionEngine.Python
label_def.expression = "[Name]"
label_def.name = 'My Label Class'
...
aprx.save()&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:43:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622761#M74348</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T17:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622786#M74351</link>
      <description>&lt;P&gt;Okay, I had some more time to look at this.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Get layer
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
lay = mp.listLayers("label")[0]
# Get definition
laycim = lay.getDefinition("V3")
# For each label class, do the following
for lc in laycim.labelClasses:
    sym = lc.textSymbol.symbol
    # Change font size and style
    sym.fontFamilyName = "Arial"
    sym.fontStyleName = "Bold"
    sym.height = 25
    # Change the fill to red
    fill = sym.symbol.symbolLayers[0]
    fill.color.values = [255,0,0,255] # Turn it red and opague
    # Add an outline
    outline = arcpy.cim.CIMSymbols.CIMSolidStroke()
    outline.color = [0,100,255,255] #idk what color this is.    
    outline.width = 2
    # Overwrite current symbol with the fill and the outline
    sym.symbol.symbolLayers= [fill, outline]
# Apply the new label symbols
lay.setDefinition(laycim)&lt;/LI-CODE&gt;&lt;P&gt;This didn't take me too long, but it wasn't fun.&lt;/P&gt;&lt;P&gt;What you aren't seeing is liberal use of print(dir(variable)) to determine what I had, e.g. for the colors&lt;/P&gt;&lt;P&gt;Steps I took:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMLabelPlacement.md#cimlabelclass-1" target="_self"&gt;Label Class&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Clicked on link next to "textSymbol", took me here&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMRenderers.md#cimsymbolreference" target="_self"&gt;CIMSymbolReference&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Clicked on link next to "symbol", took me here&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/Types.md#symbol" target="_self"&gt;Symbol&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I opened up the link for "&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMSymbols.md#cimtextsymbol" target="_blank"&gt;CIMTextSymbol&lt;/A&gt;", that got me font size, style.&lt;/LI&gt;&lt;LI&gt;I clicked the link next to "symbol" and it took me here:&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMSymbols.md#cimpolygonsymbol" target="_self"&gt;CIMPolygonSymbol&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I then clicked the link next to "symbolLayers" and it took me here:&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/Types.md#symbollayer" target="_self"&gt;Symbol Layer&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I picked "&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMSymbols.md#cimsolidfill" target="_self"&gt;CIMSolidFill&lt;/A&gt;", scrolled down to "color", and clicked the link :&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/Types.md#color" target="_self"&gt;Color&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Using dir(), I know I had a &lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMColor.md#cimrgbcolor" target="_self"&gt;CIMRGBColor&lt;/A&gt; object. I change its values.&lt;/LI&gt;&lt;LI&gt;To add the stroke, I go back to the&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/Types.md#symbollayer" target="_self"&gt;SymbolLayer page&lt;/A&gt;&amp;nbsp;and look for something that matches.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I pick &lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMSymbols.md#cimsolidstroke" target="_self"&gt;SolidStroke&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;I know from a bunch of trial and error (and also print statements) that the general way to make this work is to create an empty object that I want. It's generally "arcpy.cim.----". For best results, I use a combination of the documentation linked above and the Python Window in Pro because it has intellisense&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1749664834709.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134231iF8BDED98C151CAF7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1749664834709.png" alt="AlfredBaldenweck_0-1749664834709.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;I then look at the documentation to get the attributes I want&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;And then I save the definition.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;All this to say it's a lot of work and trial and error to get what you want and you might have a much easier time applying &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm#:~:text=be%20uniquely%20named.-,pasteProperties%20(source_layer%2C%20%7Blayer_paste_properties%7D),-Parameter" target="_self"&gt;properties from another layer&lt;/A&gt;. CIM is awful and should be avoided if you can.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:05:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622786#M74351</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-06-11T18:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622790#M74352</link>
      <description>&lt;P&gt;hu, I had a crack at layer styles a couple years back and was only able to get as far as unique values, when I tried doing stuff like hatching I ran into a wall and didn't really know how to progress but having knowledge that CIM exists in my back pocket if I touch it again will be useful.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622790#M74352</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2025-06-11T18:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622799#M74354</link>
      <description>&lt;BLOCKQUOTE&gt;I use a combination of the documentation linked above and the Python Window in Pro because it has intellisense&lt;/BLOCKQUOTE&gt;&lt;P&gt;It's not actually intelisense, terrifyingly it's actually passing the contents of the REPL box to some metafunctions that live in the arcpy.utils module.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HaydenWelch_0-1749666314991.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134232i1CB0211C3A41FF8F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HaydenWelch_0-1749666314991.png" alt="HaydenWelch_0-1749666314991.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;All they do is reformat the docstring with XML tags and such. It also traverses the stack frame looking for variables defined in scope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's worth a read:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HaydenWelch_1-1749666458609.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134233i44BF809A590834D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HaydenWelch_1-1749666458609.png" alt="HaydenWelch_1-1749666458609.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:27:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622799#M74354</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T18:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change label style using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622870#M74363</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;so much. I have applied your script and solved the labeling properties issue. I can change the font, color, and size of the labels using ArcPy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Get layer
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
lay = mp.listLayers("Ottawa_Census")[0]

# Enable labeling and turn off old label classes
lay.showLabels = True
for lc_old in lay.listLabelClasses():
    lc_old.visible = False
print('Old labels turned off')

# Create new label class
lay.createLabelClass(name='Label - Python',
                     expression='[DACODE]',
                     sql_query="POP_2016 &amp;gt;= 1000",
                     labelclass_language='Python')
print('New label class created')

# Placed after creating the new label class
laycim = lay.getDefinition("V3")

# Change the label style
for lc in laycim.labelClasses:
    if lc.name == 'Label - Python':  
        sym = lc.textSymbol.symbol
        sym.fontFamilyName = "Cambria"
        sym.fontStyleName = "Bold"
        sym.height = 8

        # Set the fill color
        fill = sym.symbol.symbolLayers[0]
        fill.color.values = [255, 0, 0, 255]  # red

        # Set the outline color and width
        outline = arcpy.cim.CIMSolidStroke()
        outline.color = [0, 100, 255, 255]  # blue
        outline.width = 1.5

        # Apply the new style
        sym.symbol.symbolLayers = [fill, outline]

# Apply the new defintion
lay.setDefinition(laycim)
print('Label class style updated and applied') &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 20:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-change-label-style-using-arcpy/m-p/1622870#M74363</guid>
      <dc:creator>brusselsboy</dc:creator>
      <dc:date>2025-06-11T20:58:39Z</dc:date>
    </item>
  </channel>
</rss>

