<?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 Loop Through Multiple classificationFields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-through-multiple-classificationfields/m-p/1105961#M62595</link>
    <description>&lt;P&gt;In my Pro project, I have 8 maps with 3 layers each. I'm writing a script that iterates the layers in each map, and changes the break values of these layers. There is one more step where I'd be grateful for some direction. And that is with setting multiple &lt;EM&gt;classificationFields&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;I know how to set the break values using one classificationField, anyway. I'm not sure I'm doing this right, but in order to give each layer its particular classificationField which corresponds to that particular map I've created a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#create fields list. for every map, change the symbology based on its corresponding field
sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14', 
'VaccPercentage12to18', 'VaccPercentage14to16', 
'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using &lt;EM&gt;sym.renderer.fields&lt;/EM&gt; because it seems to allow a list, which I'm referencing from &lt;A href="https://gis.stackexchange.com/questions/352964/using-sym-renderer-fields-with-arcpy-and-arcgis-pro-gives-nameerror-attribute" target="_self"&gt;this SE post&lt;/A&gt;. In the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/classbreak-class.htm" target="_self"&gt;Pro docs&lt;/A&gt; I don't see any help with multiple fields. This will throw an error with a list:&lt;/P&gt;&lt;PRE&gt;sym.renderer.classificationField = ...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following script iterates the layers and the maps successfully, but nothing happens to the layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx = arcpy.mp.ArcGISProject(r'\\path to\TestDelete.aprx')

def values():
    for map in aprx.listMaps():
        print(f'map: {map.name}')
        layers = map.listLayers()
        for layer in layers:
            sym = layer.symbology
                    
            if hasattr(sym, 'renderer') and layer.name.startswith('BaseLayer'):
                    sym.updateRenderer('GraduatedColorsRenderer')
                    print(f'Updated Graduated colors renderer: {layer}')

                    Renderer = sym.renderer
                    classbreakvalues = [40, 45, 56.8, 100]
                    classbreaklabels = ['0-40%', '41-45%', '46-56.8%', '56.9-100%']
                    Renderer.breakCount = len(classbreakvalues)
                    print(f'Set the break count value: {layer}')
                    #Renderer.classificationMethod = 'Manual Interval'
                    
                    #create fields list. for every map, change the symbology based on its corresponding field
                    sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14', 'VaccPercentage12to18', 
                    'VaccPercentage14to16', 'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']

                    i = 0 
                    for brk in Renderer.classBreaks:
                        brk.upperBound = classbreakvalues[i]
                        brk.label = classbreaklabels[i]
                        i+=1

                    layer.symbology = sym
                    aprx.save()
values()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Oct 2021 15:22:40 GMT</pubDate>
    <dc:creator>JaredPilbeam2</dc:creator>
    <dc:date>2021-10-08T15:22:40Z</dc:date>
    <item>
      <title>Loop Through Multiple classificationFields</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-multiple-classificationfields/m-p/1105961#M62595</link>
      <description>&lt;P&gt;In my Pro project, I have 8 maps with 3 layers each. I'm writing a script that iterates the layers in each map, and changes the break values of these layers. There is one more step where I'd be grateful for some direction. And that is with setting multiple &lt;EM&gt;classificationFields&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;I know how to set the break values using one classificationField, anyway. I'm not sure I'm doing this right, but in order to give each layer its particular classificationField which corresponds to that particular map I've created a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#create fields list. for every map, change the symbology based on its corresponding field
sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14', 
'VaccPercentage12to18', 'VaccPercentage14to16', 
'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using &lt;EM&gt;sym.renderer.fields&lt;/EM&gt; because it seems to allow a list, which I'm referencing from &lt;A href="https://gis.stackexchange.com/questions/352964/using-sym-renderer-fields-with-arcpy-and-arcgis-pro-gives-nameerror-attribute" target="_self"&gt;this SE post&lt;/A&gt;. In the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/classbreak-class.htm" target="_self"&gt;Pro docs&lt;/A&gt; I don't see any help with multiple fields. This will throw an error with a list:&lt;/P&gt;&lt;PRE&gt;sym.renderer.classificationField = ...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following script iterates the layers and the maps successfully, but nothing happens to the layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx = arcpy.mp.ArcGISProject(r'\\path to\TestDelete.aprx')

def values():
    for map in aprx.listMaps():
        print(f'map: {map.name}')
        layers = map.listLayers()
        for layer in layers:
            sym = layer.symbology
                    
            if hasattr(sym, 'renderer') and layer.name.startswith('BaseLayer'):
                    sym.updateRenderer('GraduatedColorsRenderer')
                    print(f'Updated Graduated colors renderer: {layer}')

                    Renderer = sym.renderer
                    classbreakvalues = [40, 45, 56.8, 100]
                    classbreaklabels = ['0-40%', '41-45%', '46-56.8%', '56.9-100%']
                    Renderer.breakCount = len(classbreakvalues)
                    print(f'Set the break count value: {layer}')
                    #Renderer.classificationMethod = 'Manual Interval'
                    
                    #create fields list. for every map, change the symbology based on its corresponding field
                    sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14', 'VaccPercentage12to18', 
                    'VaccPercentage14to16', 'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']

                    i = 0 
                    for brk in Renderer.classBreaks:
                        brk.upperBound = classbreakvalues[i]
                        brk.label = classbreaklabels[i]
                        i+=1

                    layer.symbology = sym
                    aprx.save()
values()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 15:22:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-multiple-classificationfields/m-p/1105961#M62595</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-08T15:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Through Multiple classificationFields</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-multiple-classificationfields/m-p/1108075#M62658</link>
      <description>&lt;P&gt;A bunch of changes later I was able to get what I wanted, which is a script that changes the break values of multiple layers in multiple maps using multiple fields. I needed a counter, which until now I only copied but wasn't sure how to use. Also, don't know if this is a bug or not, but you can't give the condition for a &lt;EM&gt;GraduatedColorsRenderer&lt;/EM&gt; if it is already. You have to "reset" the renderer. I was able to do this by changing the renderer to &lt;EM&gt;SimpleRenderer&lt;/EM&gt; then back to &lt;EM&gt;GraduatedColorsRenderer&lt;/EM&gt;. And by not setting a renderer at all I didn't get any results. Also, by remove the &lt;EM&gt;save() &lt;/EM&gt;line it ran much faster.&lt;/P&gt;&lt;P&gt;Here's a working script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx = arcpy.mp.ArcGISProject('CURRENT')

#make sure fields in list are in same order as maps in project
fields =  ['VaccPercentageTotPop', 'VaccPercentage11to14', 'VaccPercentage0to18', 'VaccPercentage12to18',  
           'VaccPercentage14to16', 'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']

c = 0 # use counter to give a number to each map in for loop
for map in aprx.listMaps():
    print(f'--- map: {map.name} ---')
    layers = map.listLayers()
    for layer in layers:
        print(f'layer: {layer.name}')
        sym = layer.symbology 
        #reset renderer
        sym.updateRenderer('SimpleRenderer')
        sym.updateRenderer('GraduatedColorsRenderer')

        if hasattr(sym, 'renderer') and layer.name.startswith('BaseLayer'):
            Renderer = sym.renderer
            Renderer.classificationField = fields[c]

            classbreakvalues = [40, 45, 60, 100]
            classbreaklabels = ['0-40%', '41-45%', '46-60%', '60.4%-100%']
            Renderer.breakCount = len(classbreakvalues)

            i = 0 
            for brk in Renderer.classBreaks:
                brk.upperBound = classbreakvalues[i]
                brk.label = classbreaklabels[i]
                i+=1

                layer.symbology = sym

#                     aprx.save()
    c+=1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 18:50:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-multiple-classificationfields/m-p/1108075#M62658</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-15T18:50:47Z</dc:date>
    </item>
  </channel>
</rss>

