<?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 Problem with arcpy.mapping Title and Legend in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710246#M55056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Every body&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new at python and I have problem adding a title and legend to the layout by arcpy.mapping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried ESRI's samples which where too complicated (Specifically the Legend Example!) and I could not add the legend a simple title to map!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you please let me know how i can do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I also need to know how I can resize or position the data frame in map layout.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used this code to create title which didn't add any thing&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Test\Map.mxd")
#search for ???Title Block??? and if found move to desired location
for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
if elm.name == "My Map":
elm.elementPositionX = 4.75
elm.elementPositionY = 10.5
mxd.save()
del mxd
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Mar 2011 14:32:09 GMT</pubDate>
    <dc:creator>BernardoG_</dc:creator>
    <dc:date>2011-03-08T14:32:09Z</dc:date>
    <item>
      <title>Problem with arcpy.mapping Title and Legend</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710246#M55056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Every body&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new at python and I have problem adding a title and legend to the layout by arcpy.mapping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried ESRI's samples which where too complicated (Specifically the Legend Example!) and I could not add the legend a simple title to map!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you please let me know how i can do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I also need to know how I can resize or position the data frame in map layout.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used this code to create title which didn't add any thing&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Test\Map.mxd")
#search for ???Title Block??? and if found move to desired location
for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
if elm.name == "My Map":
elm.elementPositionX = 4.75
elm.elementPositionY = 10.5
mxd.save()
del mxd
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2011 14:32:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710246#M55056</guid>
      <dc:creator>BernardoG_</dc:creator>
      <dc:date>2011-03-08T14:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with arcpy.mapping Title and Legend</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710248#M55058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this in the Python window:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;print ", ".join(el.name for el in arcpy.mapping.ListLayoutElements(activeMXD))
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;this will list the names of every layout element in the document. It may be the case that the name is wrong in the script or it is not found because it is in a group element.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are using the raw flag on a string, you don't need to escape backslashes. Use one of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("H:\\My Files\\Test\\Project.mxd")&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument(r"H:\My Files\Test\Project.mxd")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, ensure the element is being found:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Test\Map.mxd")
#search for �??Title Block�?� and if found move to desired location
for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
if elm.name == "My Map":
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "FOUND IT!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.elementPositionX = 4.75
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.elementPositionY = 10.5&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710248#M55058</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-12T06:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with arcpy.mapping Title and Legend</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710247#M55057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I also tried this code&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mapTitleText = "Salam"
activeMXD = arcpy.mapping.MapDocument("CURRENT")
# Identify the map title element.
mapTitle = arcpy.mapping.ListLayoutElements(activeMXD, "TEXT_ELEMENT", "mapTitle")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;which I get the following error!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.IndexError'&amp;gt;: list index out of range&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Title).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed at Tue Mar 08 09:13:33 2011 (Elapsed Time: 0.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and when I run this code to create legend &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os
import sys
import arcpy
lyr&amp;nbsp; = "roads" 
mxd = arcpy.mapping.MapDocument(r"H:\\My Files\\Test\\Project")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
lyr = arcpy.mapping.Layer(r"vanroads")
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]
legend.autoAdd = True
legend.adjustColumnCount(2)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;I am getting this error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Running script Legend...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.AssertionError'&amp;gt;: Invalid MXD filename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Legend).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed at Tue Mar 08 09:45:23 2011 (Elapsed Time: 0.00 seconds)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-title-and-legend/m-p/710247#M55057</guid>
      <dc:creator>BernardoG_</dc:creator>
      <dc:date>2021-12-12T16:50:09Z</dc:date>
    </item>
  </channel>
</rss>

