<?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 Dynamic Text Based on Variable? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262466#M20193</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I guess this question is two fold:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Is there a way to make dynamic text that is based on a variable? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. If so how do I do it and set the variable # using python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My situation is I have a map ID # in the top right of my map. As of now I manually change the ID # for every map that I make, I want this to be automated. I have a list of the ID's so I can make a loop if I can figure out how to set the text to be based on a variable and then learn how to set that variable using ESRI's python. Thanks in advance&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 May 2012 21:35:07 GMT</pubDate>
    <dc:creator>JoelMadero</dc:creator>
    <dc:date>2012-05-14T21:35:07Z</dc:date>
    <item>
      <title>Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262466#M20193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I guess this question is two fold:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Is there a way to make dynamic text that is based on a variable? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. If so how do I do it and set the variable # using python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My situation is I have a map ID # in the top right of my map. As of now I manually change the ID # for every map that I make, I want this to be automated. I have a list of the ID's so I can make a loop if I can figure out how to set the text to be based on a variable and then learn how to set that variable using ESRI's python. Thanks in advance&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2012 21:35:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262466#M20193</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2012-05-14T21:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262467#M20194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's what I do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var_text = "Some title/number etc"
element_name = "ID"
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == element_name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = (var_text)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262467#M20194</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T12:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262468#M20195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here's what I do.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var_text = "Some title/number etc"
element_name = "ID"
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == element_name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = (var_text)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the reply. How do I actually set the dynamic text to be the element named "ID". I think otherwise I get it, thanks again appreciate all the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262468#M20195</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2021-12-11T12:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262469#M20196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Right click on the text element and select properties.&amp;nbsp; Go to the Size and Position tab.&amp;nbsp; Set the Element Name there.&amp;nbsp; Be sure all elements that you want to find have a unique name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 14:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262469#M20196</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-05-15T14:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262470#M20197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Right click on the text element and select properties.&amp;nbsp; Go to the Size and Position tab.&amp;nbsp; Set the Element Name there.&amp;nbsp; Be sure all elements that you want to find have a unique name.&lt;BR /&gt;&lt;BR /&gt;Jeff&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nevermind, need to read directions more thoroughly. going to try now&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 14:37:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262470#M20197</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2012-05-15T14:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262471#M20198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;so it works the first time but fails to change the text when you run the same code a second time:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var_text = "1200"
&amp;gt;&amp;gt;&amp;gt; element_name = "map_ID"
&amp;gt;&amp;gt;&amp;gt; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name):
...&amp;nbsp; if elm.name == element_name:
...&amp;nbsp;&amp;nbsp; elm.Text = (var_text)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;first time no problem at all, second time I just change var_text to some other thing "1201" for instance and it doesn't update the text. Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: More info, if I double click on text and then exit properties, then run the script again with a different # for var_text it works. This defeats the purpose of the script though (automate the maps) so hoping to find a way around it&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262471#M20198</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2021-12-11T12:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262472#M20199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if this is the sort of thing you were looking for but I might have something that will work for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, it requires a look up table containing map names and the text you want displayed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To use the code, the maps you want to run the code on should ALL contain the same text&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for the element you want to change. For example, when I was testing the code I had the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;text '&amp;lt;TextVariable&amp;gt;' on each map and it was set to be the text replaced by what was&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;stored in the look up table for that map document.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So in my test, the text that said '&amp;lt;TextVariable&amp;gt;' became 'Map 001' in Map1.mxd, it became &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Map 002' in Map2.mxd and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This solution would require you to change the text after the map is completed. Also, the code can't be run &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;on a map that is currently open.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#============================================
# Change Text Based Using Look Up Table
#============================================

import arcpy
import os

mxds = [r"C:\My_Stuff\GIS\Text\Map1.mxd","C:\My_Stuff\GIS\Text\Map2.mxd"] #List of mxds
table = [r"C:\My_Stuff\GIS\Text\DynamicText.gdb\LookupText"] # Lookup table

for mxd in mxds:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapp = arcpy.mapping.MapDocument(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = row.getValue("MapName") #Fieldname containing map names
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if val + ".mxd" == os.path.basename(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txt = row.getValue("Text") #Fieldname containing text string
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txt_elms = arcpy.mapping.ListLayoutElements(mapp,"TEXT_ELEMENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for elm in txt_elms:
&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; if elm.text == "&amp;lt;TextVariable&amp;gt;": #Text in all maps to be replaced
&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; elm.text = txt
&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; mapp.save()
&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; del rows, row
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also set the code to look for element names rather than text&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, while I didn't have any trouble with the code, if you use the code you may want to test it on copies&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;of you maps first given that it saves the changes made.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262472#M20199</guid>
      <dc:creator>BenjaminGale</dc:creator>
      <dc:date>2021-12-11T12:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262473#M20200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;so it works the first time but fails to change the text when you run the same code a second time:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var_text = "1200"
&amp;gt;&amp;gt;&amp;gt; element_name = "map_ID"
&amp;gt;&amp;gt;&amp;gt; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name):
...&amp;nbsp; if elm.name == element_name:
...&amp;nbsp;&amp;nbsp; elm.Text = (var_text)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;first time no problem at all, second time I just change var_text to some other thing "1201" for instance and it doesn't update the text. Any ideas?&lt;BR /&gt;&lt;BR /&gt;Edit: More info, if I double click on text and then exit properties, then run the script again with a different # for var_text it works. This defeats the purpose of the script though (automate the maps) so hoping to find a way around it&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this. The line elm.Text won't work. Capitalization is important, as is indenting. Though in this case, the indentation you used was fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT",element_name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = var_text&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262473#M20200</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T12:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262474#M20201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try this. The line elm.Text won't work. Capitalization is important, as is indenting. Though in this case, the indentation you used was fine.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT",element_name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = var_text&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That did the trick. I've never used a language that has two different actions dependent on capitalization. If anything it just fails if it's not capitalized right but in this case it worked the first time, failed the second. Very strange, but problem solved &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks for the reply&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262474#M20201</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2021-12-11T12:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Text Based on Variable?</title>
      <link>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262475#M20202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try this. The line elm.Text won't work. Capitalization is important, as is indenting. Though in this case, the indentation you used was fine.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT",element_name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = var_text&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: Oh you mean an actual selection. I really am trying to avoid selecting as it's so much slower than what I'm doing now (definition query, zoom to layer). Not sure why the speed difference but it's at least 50% faster avoiding selection and with 250+ maps being printed from a mid range computer, 50% is a lot of time saved&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:52:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dynamic-text-based-on-variable/m-p/262475#M20202</guid>
      <dc:creator>JoelMadero</dc:creator>
      <dc:date>2021-12-11T12:52:33Z</dc:date>
    </item>
  </channel>
</rss>

