<?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: Code in field calculator does not 'refresh' in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213402#M65596</link>
    <description>&lt;P&gt;Attribute Rules in ArcGIS Pro is the best solution here. I will add that you can write a Python script that to perform the calculate field operation on your data and &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/analytics/schedule-a-python-script-or-model-to-run-at-a-prescribed-time-2019-update/" target="_self"&gt;schedule it to run as a task&lt;/A&gt;. So every night, or even every hour, the script could run to calculate the values.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 14:16:53 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2022-09-16T14:16:53Z</dc:date>
    <item>
      <title>Code in field calculator does not 'refresh'</title>
      <link>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213322#M65594</link>
      <description>&lt;P&gt;Hello. I have a python code in the ArcMap field calculator that translates numbers in the Id-column&amp;nbsp; to text in another column in the same attribute table. In the pre-logic-script It looks like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(Id):
    if (Id == 0):
        return "AAA"
    if (Id == 1):
        return "BBB"
    if (Id == 2):
        return "CCC"
    if (Id == 3):
        return "DDD"
    if (Id == 4):
        return "EEE"
    if (Id == 5):
        return "FFF"
    if (Id == 6):
        return "GGG"
    else:
        return "&amp;lt;Null&amp;gt;"&lt;/LI-CODE&gt;&lt;P&gt;and in the other box:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;reclass(!Id!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that this code disapears every time I shut down arcMap, and have to be re-loaded when I add anything. For example if I add an object with id-class 2 it doesn't automatically writes CCC in the new column iuntill I have re-runed the script.&lt;/P&gt;&lt;P&gt;Is there some way I can automatically run this script as soon as I open / change anything the attribute table?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 09:25:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213322#M65594</guid>
      <dc:creator>AndersKMG</dc:creator>
      <dc:date>2022-09-16T09:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Code in field calculator does not 'refresh'</title>
      <link>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213347#M65595</link>
      <description>&lt;P&gt;For ArcMap, there's the&amp;nbsp;&lt;A href="https://solutions.arcgis.com/shared/help/attribute-assistant/" target="_blank"&gt;Attribute Assistant.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For ArcGIS Pro, there are &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm" target="_self"&gt;Attribute Rules&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:25:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213347#M65595</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-16T11:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code in field calculator does not 'refresh'</title>
      <link>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213402#M65596</link>
      <description>&lt;P&gt;Attribute Rules in ArcGIS Pro is the best solution here. I will add that you can write a Python script that to perform the calculate field operation on your data and &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/analytics/schedule-a-python-script-or-model-to-run-at-a-prescribed-time-2019-update/" target="_self"&gt;schedule it to run as a task&lt;/A&gt;. So every night, or even every hour, the script could run to calculate the values.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 14:16:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1213402#M65596</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-09-16T14:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Code in field calculator does not 'refresh'</title>
      <link>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1215052#M65658</link>
      <description>&lt;P&gt;Two tips for you: using "&amp;lt;Null&amp;gt;" will enter it as a string and not a true Null.&lt;/P&gt;&lt;P&gt;You can avoid chaining if statements by using a switch case (dictionary lookup) construct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(Id):
    classDict = {
        0: "AAA",
        1: "BBB",
        2: "CCC",
        3: "DDD",
        4: "EEE",
        5: "FFF",
        6: "GGG"}

    return classDict.get(Id) # &amp;lt;- returns the value if found in the dictionary or the default true Null

    #return classDict.get(Id, '&amp;lt;Null&amp;gt;') # &amp;lt;- returns the value if found in the dictionary or the string &amp;lt;Null&amp;gt; as the default&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 13:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-field-calculator-does-not-refresh/m-p/1215052#M65658</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-22T13:07:53Z</dc:date>
    </item>
  </channel>
</rss>

