<?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: Help with managing legend style in arcpy.maooing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106444#M8224</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After adding the lyr files to the map, use layer references to layers in the map, not lyr files on disk, in updateItem. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Temp\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr") arcpy.mapping.AddLayer(df, lyrFile, "TOP") styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items")[0] legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0] lyr = arcpy.mapping.ListLayers(mxd, 'NE_Lakes', df)[0] # the name in the TOC for Rivers.lyr legend.updateItem(lyr, styleItem) # use lyr, not lyrFile arcpy.mapping.ExportToPDF(mxd, 'temp.pdf') del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We made the same error in some of our doc samples, which I will change now. Sorry if the samples sent you down the wrong path.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Sep 2012 16:25:20 GMT</pubDate>
    <dc:creator>JeffMoulds</dc:creator>
    <dc:date>2012-09-27T16:25:20Z</dc:date>
    <item>
      <title>Legend style in arcpy.mapping - Index Error: 0</title>
      <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106443#M8223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;All, &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am currently working in ArcMap 10.1. I am trying to add layers to a map, then change the legend's style and location. Below is a sample code. legend variable is working, and I can move it around as a LayoutElement. However, when I want to update the style I keep getting an Index Error: 0. I've been trying my own custom style, but can't even get it to work with the ESRI.style. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's the code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="plain"&gt;import arcpy from arcpy import env arcpy.env.overwriteOutput = True import os&amp;nbsp; mxd = arcpy.mapping.MapDocument ("C:\\TestFolder\\Untitled.mxd") df = arcpy.mapping.ListDataFrames (mxd, "Layers")[0]&amp;nbsp; style = "ESRI.style" lyr1 = arcpy.mapping.Layer("C:\\TestFolder\\GriDSSAT_Counties.lyr") lyr2 = arcpy.mapping.Layer("C:\\TestFolder\\TestLayer\\LGI_20120821.lyr") lyr3 = arcpy.mapping.Layer("C:\\TestFolder\\States.lyr") styleItem = arcpy.mapping.ListStyleItems(style, "Legend Items")[0] legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0] legend.autoAdd = False arcpy.mapping.AddLayer(df, lyr1) legend.autoAdd = True arcpy.mapping.AddLayer(df, lyr2, "BOTTOM") legend.autoAdd = False arcpy.mapping.AddLayer(df, lyr3, "BOTTOM")&amp;nbsp; print styleItem&amp;nbsp; legend.updateItem(lyr2, styleItem)&amp;nbsp;&amp;nbsp; legend.title = "Whoala"&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF (mxd, "C:\\TestFolder\\PDFFolder\\Test.pdf")&lt;/PRE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The error message I receive is as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\TestFolder\Scripts\legend.py", line 24, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.updateItem(lyr2, styleItem)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", line 772, in updateItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.updateItem(*gp_fixargs((legend_item_layer, legend_item_style_item, preserve_style_sizes, use_visible_extent, show_feature_count, use_ddp_extent, index), True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IndexError: 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any insight on how to fix this &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Lee&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message was edited by: Curtis Price 2014.10.25 typo in title&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2012 13:53:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106443#M8223</guid>
      <dc:creator>LeeEllenburg</dc:creator>
      <dc:date>2012-09-27T13:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with managing legend style in arcpy.maooing</title>
      <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106444#M8224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After adding the lyr files to the map, use layer references to layers in the map, not lyr files on disk, in updateItem. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Temp\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr") arcpy.mapping.AddLayer(df, lyrFile, "TOP") styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items")[0] legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0] lyr = arcpy.mapping.ListLayers(mxd, 'NE_Lakes', df)[0] # the name in the TOC for Rivers.lyr legend.updateItem(lyr, styleItem) # use lyr, not lyrFile arcpy.mapping.ExportToPDF(mxd, 'temp.pdf') del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We made the same error in some of our doc samples, which I will change now. Sorry if the samples sent you down the wrong path.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2012 16:25:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106444#M8224</guid>
      <dc:creator>JeffMoulds</dc:creator>
      <dc:date>2012-09-27T16:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with managing legend style in arcpy.maooing</title>
      <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106445#M8225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Funny story... I had to move projects after I posted this. I just lately have had enough time to get back to what I was doing and I came back to the same error. I googled it and found this.... the question I asked months ago!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, this works great!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 21:15:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106445#M8225</guid>
      <dc:creator>LeeEllenburg</dc:creator>
      <dc:date>2013-02-07T21:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with managing legend style in arcpy.maooing</title>
      <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106446#M8226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Hello,&lt;/P&gt;&lt;P&gt;I get the same error but I believe I am using a reference instead of the layer as I used arcpy.mapping.Layer() to reference the layer "icecurrentlayer".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what am i doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here ist the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14142476940695413 jive_text_macro" jivemacro_uid="_14142476940695413"&gt;
&lt;P&gt;arcpy.MakeRasterLayer_management(wdir&amp;nbsp; + "\\" + "Day_" + str(j) + "_ice_" + i + "cm.tif", "icecurrentlayer", "#")&lt;/P&gt;
&lt;P&gt;arcpy.ApplySymbologyFromLayer_management("icecurrentlayer", "D:\\R_working_directory\\hales_and_roering_2007\\SGRD\\colormodel2.lyr")&lt;/P&gt;
&lt;P&gt;reficecurrentlayer = arcpy.mapping.Layer("icecurrentlayer")&lt;/P&gt;
&lt;P&gt;arcpy.mapping.AddLayer(data_frame = dfs[di[1].index(i)], add_layer = reficecurrentlayer, add_position = "TOP")# Provides the ability to add a layer to a data frame within a map document (.mxd) using simple placement options&lt;/P&gt;
&lt;P&gt;# Change look of Legend for ice layers: You can look up the style_file_path, etc in the Style manager (GUI -&amp;gt; Customize)&lt;/P&gt;
&lt;P&gt;styleItem = arcpy.mapping.ListStyleItems("C:/Program Files (x86)/ArcGIS/Desktop10.2/Styles/ESRI.ServerStyle", "Legend Items", "Horizontal Single Symbol Description Only")[0]&lt;/P&gt;
&lt;P&gt;legend.updateItem(reficecurrentlayer, styleItem)&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Oct 2014 14:39:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106446#M8226</guid>
      <dc:creator>LudwigHilger</dc:creator>
      <dc:date>2014-10-25T14:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with managing legend style in arcpy.maooing</title>
      <link>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106447#M8227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My guess is a list is coming up empty. A good way to test these things is to run them from the ArcMap python command line so you can see what you're getting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, it's better not to hard code the install folder, here's how you can avoid that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_1414298208800872" jivemacro_uid="_1414298208800872" modifiedtitle="true"&gt;
&lt;P&gt;InstallDir = arcpy.GetInstallInfo("desktop")["InstallDir"]&lt;/P&gt;
&lt;P&gt;styleItem =&amp;nbsp; arcpy.mapping.ListStyleItems(&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InstallDir + "/Styles/ESRI.ServerStyle",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Legend Items",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Horizontal Single Symbol Description Only")[0]&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Oct 2014 04:37:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-style-in-arcpy-mapping-index-error-0/m-p/106447#M8227</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-26T04:37:43Z</dc:date>
    </item>
  </channel>
</rss>

