<?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: Looking to add a legends using arcpy in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154555#M1712</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you control font size/style in a legend with arcpy?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Nov 2017 21:54:50 GMT</pubDate>
    <dc:creator>AlexCarrier2</dc:creator>
    <dc:date>2017-11-20T21:54:50Z</dc:date>
    <item>
      <title>Looking to add a legends using arcpy</title>
      <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154551#M1708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to add a legend to a map layout using arcpy. after going through the tutorials I have used the following code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.AddLayer(df, lyrFile, "TOP")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "NewDefaultLegendStyle")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;legend.updateItem(lyrFile, styleItem)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but everytime I run this code I found an error :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'list' object has no attribute 'updateItem'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kindly help to resolve this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new to map automation and using Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Swati&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2014 06:45:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154551#M1708</guid>
      <dc:creator>swatisaini</dc:creator>
      <dc:date>2014-01-12T06:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to add a legends using arcpy</title>
      <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154552#M1709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The code sample you have below is identical to the help sample for the Legend Class.&amp;nbsp; I don't see any changes and wonder if your data supports these lines of code.&amp;nbsp; Is this the actual code you are running aginst your data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm confused by the error.&amp;nbsp; This line should return a proper legend element, if one exists:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154552#M1709</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T08:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to add a legends using arcpy</title>
      <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154553#M1710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, the code is same as is given in the Arcgis 10.1 Help as a sample code and i tired running this after creating a same folder ,Layer and mxd.But After i ran this code it gave me the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'list' object has no attribute 'updateItem'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can;t figure out what I am doing wrong. However, my aim is to add legend to the map (around 50 maps) and the legend is different for each of the map.Kindly tell me what should i do to automate this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to save a legend file , so that we can add it using arcpy..??? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Swati&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 09:01:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154553#M1710</guid>
      <dc:creator>swatisaini</dc:creator>
      <dc:date>2014-01-15T09:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to add a legends using arcpy</title>
      <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154554#M1711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't see the error in your code.&amp;nbsp; Are you running this from ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can NOT create new legends with arcpy.mapping.&amp;nbsp; You can only alter existing legends on a page layout.&amp;nbsp; If you add layers to a data frame, those layers can automatically be added to the legend.&amp;nbsp; You can control column count, positioning, etc&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 13:46:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154554#M1711</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2014-01-16T13:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to add a legends using arcpy</title>
      <link>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154555#M1712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you control font size/style in a legend with arcpy?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 21:54:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/looking-to-add-a-legends-using-arcpy/m-p/154555#M1712</guid>
      <dc:creator>AlexCarrier2</dc:creator>
      <dc:date>2017-11-20T21:54:50Z</dc:date>
    </item>
  </channel>
</rss>

