<?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 Text Elements and Graphic Element don&amp;acute;t show updates in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/text-elements-and-graphic-element-don-acute-t-show/m-p/721972#M55884</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 just found out about the intriguing possibility to dynamically change layout elements with arcpy. unfortunately i can´t seem to get it working correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i found this neat example on how to export different thematic layer to different pages in a pdf and would like to change a text element and it´s position based on the current layer´s name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;below is the edited example script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import os, arcpy


#Specify output path and final output PDF
outPath = r"e:\test\info\\"
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport.pdf")

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r"e:\test\testspi.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# specifiy the layout elements i want to change
textElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textfield")[0]
titleBox = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "boxA4h")[0]


#Turn on visibility for each theme and export the page
lyrList = ["spJ_sappi", "sappi", "sappi_5klassen"]
for lyrName in lyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # change the textbox´s text to the current layername and it´s position to be centered within the box
&amp;nbsp;&amp;nbsp;&amp;nbsp; textElem.text = str(lyrName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; textElem.elementPositionX = ((titleBox.elementWidth - textElem.elementWidth)/2)+titleBox.elementPositionX
&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyrName," ",textElem.elementPositionX
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export each theme to a temporary PDF and append to the final PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpPdf = outPath + lyrName + "_temp.pdf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(tmpPdf):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; finalPdf.appendPages(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Turn off layer visibility and clean up for next pass through the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr, tmpPdf
del mxd, df, finalPdf&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;changing the text of the box works fine, but the position won´t (i´ve also tried to save the mxd after each pass), as long as i run this outside of arcmap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the only way to get it to work is by running it inside arcmap and changing the mxd to "CURRENT". &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;edit:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oh man do i feel stupid now...it´s textElem.elementPositionX not textElem.PositionX&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Sep 2011 06:22:57 GMT</pubDate>
    <dc:creator>RaphaelR</dc:creator>
    <dc:date>2011-09-07T06:22:57Z</dc:date>
    <item>
      <title>Text Elements and Graphic Element don´t show updates</title>
      <link>https://community.esri.com/t5/python-questions/text-elements-and-graphic-element-don-acute-t-show/m-p/721972#M55884</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 just found out about the intriguing possibility to dynamically change layout elements with arcpy. unfortunately i can´t seem to get it working correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i found this neat example on how to export different thematic layer to different pages in a pdf and would like to change a text element and it´s position based on the current layer´s name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;below is the edited example script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import os, arcpy


#Specify output path and final output PDF
outPath = r"e:\test\info\\"
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport.pdf")

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r"e:\test\testspi.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# specifiy the layout elements i want to change
textElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textfield")[0]
titleBox = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "boxA4h")[0]


#Turn on visibility for each theme and export the page
lyrList = ["spJ_sappi", "sappi", "sappi_5klassen"]
for lyrName in lyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # change the textbox´s text to the current layername and it´s position to be centered within the box
&amp;nbsp;&amp;nbsp;&amp;nbsp; textElem.text = str(lyrName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; textElem.elementPositionX = ((titleBox.elementWidth - textElem.elementWidth)/2)+titleBox.elementPositionX
&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyrName," ",textElem.elementPositionX
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export each theme to a temporary PDF and append to the final PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpPdf = outPath + lyrName + "_temp.pdf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(tmpPdf):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; finalPdf.appendPages(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Turn off layer visibility and clean up for next pass through the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr, tmpPdf
del mxd, df, finalPdf&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;changing the text of the box works fine, but the position won´t (i´ve also tried to save the mxd after each pass), as long as i run this outside of arcmap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the only way to get it to work is by running it inside arcmap and changing the mxd to "CURRENT". &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;edit:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oh man do i feel stupid now...it´s textElem.elementPositionX not textElem.PositionX&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 06:22:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/text-elements-and-graphic-element-don-acute-t-show/m-p/721972#M55884</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2011-09-07T06:22:57Z</dc:date>
    </item>
  </channel>
</rss>

