<?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: Arcpy For Loop to Apply Symbology to Multiple Layers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313193#M24341</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;line 7... the current mxd... but I think there is more fundamental to just fixing up a for loop which contains a try except block which doesn't return any useful information in its current form.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 Mar 2016 16:08:33 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-03-14T16:08:33Z</dc:date>
    <item>
      <title>Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313188#M24336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have multiple layers in ArcMap that I want to import a symbology for from a layer file. The code I have is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

# Reference current MXD and dataframe. 
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
layers = arcpy.mapping.ListLayers(mxd,"",df)

# Layer file symbology to be imported is in.
in_symbology_layer = arcpy.mapping.Layer("C:\LayerStyles\LayerFile.lyr")

# Layer to receive imported symbology.
in_layer = arcpy.mapping.ListLayers(mxd, "", df)[0]

# For loop to import symbology to all layers in current MXD.
for lyr in layers:
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer)
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Failed to import symbology for: " +lyr.name

# Refreshes Table of Contents.
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code seems to work in parts, as the output I get is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Failed to import symbology for: Layer1&lt;/P&gt;&lt;P&gt;"Failed to import symbology for: Layer2&lt;/P&gt;&lt;P&gt;"Failed to import symbology for: Layer3..."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For loops are my Achilles Heel so any assistance would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;DK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:56:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313188#M24336</guid>
      <dc:creator>DarrochKaye</dc:creator>
      <dc:date>2021-12-11T14:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313189#M24337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you retrieve the first layer in the data frame and are trying to apply the symbology from layer on disk.&amp;nbsp; Have you confirmed that the layers are of the same type so that the symbology will apply?&lt;/P&gt;&lt;P&gt;(&lt;SPAN class="string"&gt;"C:\LayerStyles\LayerFile.lyr"&lt;/SPAN&gt;)&amp;nbsp; should be (&lt;STRONG&gt;r&lt;/STRONG&gt;&lt;SPAN class="string"&gt;"C:\LayerStyles\LayerFile.lyr"&lt;/SPAN&gt;)&amp;nbsp; raw formatted with the "r" just be sure it can find the layer.&amp;nbsp; So, dump the try except block so you get a real error message, confirm that the layer can be found and use a check to ensure that the symbology from that layer is appropriate for the layer it is trying to apply it to.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 15:47:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313189#M24337</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-14T15:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313190#M24338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Change line 18 your using a list instead of&amp;nbsp; a layer&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;in_layer to lyr&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/listlayers.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/listlayers.htm"&gt;ListLayers—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 15:50:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313190#M24338</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-03-14T15:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313191#M24339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in_layer = arcpy.mapping.ListLayers(mxd, "", df)[&lt;SPAN class="number"&gt;0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [0] should mean he is getting the first layer in the list... if that is not what he wants, then the question is muddier&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 15:52:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313191#M24339</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-14T15:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313192#M24340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your right, I missed [0] on the end. So why the loop?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 16:05:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313192#M24340</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-03-14T16:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313193#M24341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;line 7... the current mxd... but I think there is more fundamental to just fixing up a for loop which contains a try except block which doesn't return any useful information in its current form.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 16:08:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313193#M24341</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-14T16:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313194#M24342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;My apologies if my original post was unclear. The code I posted was my attempt based on other pieces of code I know work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;I want to apply the symbology that is stored in a layer file to all layers I currently have open in ArcMap in a Group Layer. They are all polygon files and all have the same fields so there is no error in that regard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;Thanks,&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;DK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 16:51:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313194#M24342</guid>
      <dc:creator>DarrochKaye</dc:creator>
      <dc:date>2016-03-14T16:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313195#M24343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So far I have got the following code to work on a single, specified layer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# Reference current MXD and dataframe.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
layers = arcpy.mapping.ListLayers(mxd)

# Layer file symbology to be imported is in.
in_symbology_layer = arcpy.mapping.Layer(r"C:\LayerStyles\LayerFile.lyr")

# Layer to receive imported symbology.
in_layer = arcpy.mapping.ListLayers(mxd, "09-03-2016 00_00_00", df)[0]

arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer)

# Refreshes Table of Contents.
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...but what I would like is to apply this code to multiple layers, e.g. layers in a Group Layer, rather than a uniquely specified layer, e.g. "09-03-2016 00_00_00".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;DK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:56:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313195#M24343</guid>
      <dc:creator>DarrochKaye</dc:creator>
      <dc:date>2021-12-11T14:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313196#M24344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;all_layers = arcpy.mapping.ListLayers(mxd, &lt;SPAN class="string"&gt;"09-03-2016 00_00_00", df)&amp;nbsp;&amp;nbsp; # note ... no [0]&lt;/SPAN&gt;
&lt;SPAN class="string"&gt;in_layer = all_layers[0]&amp;nbsp; # the first layer&lt;/SPAN&gt;
&lt;SPAN class="string"&gt;for layer in all_layers:&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management(layer, in_symbology_layer)&amp;nbsp; # guessing since arc-free&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:56:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313196#M24344</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313197#M24345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Solution:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# Reference current MXD and dataframe.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# Layer file symbology to be imported.
in_symbology_layer = arcpy.mapping.Layer(r"C:\LayerStyles\LayerFile.lyr")

# Layer to receive imported symbology.
all_layers = arcpy.mapping.ListLayers(mxd)

for layer in all_layers: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management(layer, in_symbology_layer)

# Refreshes Table of Contents.
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks to all those who contributed.&lt;/P&gt;&lt;P&gt;DK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:56:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313197#M24345</guid>
      <dc:creator>DarrochKaye</dc:creator>
      <dc:date>2021-12-11T14:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy For Loop to Apply Symbology to Multiple Layers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313198#M24346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi DK -&lt;/P&gt;&lt;P&gt;I used this script with great success on multiple mxds with several hundred layers. I would like to know if it is possible to apply this to mxds with group layers. I've looked in the forums but my python knowledge is not good enough to figure this out. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sheila&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 16:10:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-for-loop-to-apply-symbology-to-multiple/m-p/313198#M24346</guid>
      <dc:creator>SheilaBrown</dc:creator>
      <dc:date>2016-07-19T16:10:08Z</dc:date>
    </item>
  </channel>
</rss>

