<?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: Calculate Field not working when iterating through a list of feature classes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176163#M64611</link>
    <description>&lt;P&gt;Yes, at this point I am pretty sure that it is something about the field being deleted that is causing the issue; when I comment that out, it's fine, then the issue occurs on the next run immediately after uncommenting it. I have edited my original post, and mentioned this in my last comment.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I'm actually watching it create the field it needs in each FC if it isn't already there, so it's definitely working on the right things.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Why not move the calculate field directly below the add field, and do it in one iteration.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This is what I mean (from the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;Calculate Field Documentation page&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;If a field with the specified name does not exist in the input table, it will be added.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It's all being done in the same iteration. &lt;SPAN&gt;The tool is supposed to add a field, calculate it, and then delete it at the end because the field is not needed any longer. it seems that the deletion is causing issues.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The script &lt;STRONG&gt;is&lt;/STRONG&gt; working on the right feature classes; I can tell because it's creating fields when trying to calculate them. Like I said, something about that field being deleted at the end of the tool causes the next run to be messed up.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To reiterate, with DeleteField() active at the end of the script, the Field Calculation will either not calculate at all or calculate the field as Null, with the exception of the first feature class in the list, which is fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This behavior begins as soon as DeleteField() is active, and can only be fixed by turning it off and restarting Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you are wondering why I keep running this on the same set of data over and over, it's for testing purposes.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 21 May 2022 00:29:25 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-05-21T00:29:25Z</dc:date>
    <item>
      <title>Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176117#M64607</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to calculate the same field in multiple feature classes in a list.&lt;/P&gt;&lt;P&gt;The first time it runs after opening Pro, it works great. However, each time after that, it will calculate the field for the first feature class in the list and ignore the rest.&lt;/P&gt;&lt;P&gt;Does anyone have any ideas as to what might be causing it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FCList= [FC1, FC2]
for FC in FCList:
    arcpy.management.CalculateField(FC, 'SampleField', '"Hello world"', 'ARCADE')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current best guess is that later in the script I delete the field that's being calculated, and that's what's causing it to freak out. Does anyone have any ideas for how to prevent that from happening?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FCList= [FC1, FC2]
for FC in FCList:
    arcpy.management.CalculateField(FC, 'SampleField', '"Hello world"', 'ARCADE')

#code
#code
'''This is where the problem is, I think?'''
arcpy.management.DeleteField(FC, 'SampleField')&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 20 May 2022 22:43:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176117#M64607</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-05-20T22:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176127#M64608</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not showing enough code to have an idea as to what is in the FCList (what is FC1 equal to, etc.).&lt;/P&gt;&lt;P&gt;So, if you use the following code, do you see it listing ALL the feature classes?&lt;/P&gt;&lt;P&gt;Once you get it listing the appropriate FC's, then you can put the CalculateField back in there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;FCList= [FC1, FC2]
for FC in FCList:
    print(FC.name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 21:19:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176127#M64608</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-05-20T21:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176150#M64609</link>
      <description>&lt;P&gt;This is a stripped down example, but yes.&lt;/P&gt;&lt;P&gt;I'm adding some functionality in the middle of the script, and my current set-up works for everything else I want to do. The FCList is a list of layers returned as a Parameter from the scripting tool.&lt;/P&gt;&lt;P&gt;In this case, I'm actually watching it create the field it needs in each FC if it isn't already there, so it's definitely working on the right things. I have also experimented with defining FC as FC.datasource to see if that was part of the problem, but it didn't really change anything.&lt;/P&gt;&lt;P&gt;This behaviour occurs regardless of if I'm using a scripting tool or the Python window in Pro.&lt;/P&gt;&lt;P&gt;Best I can tell, (and this is wildly inconsistent as to the exact numbers, which has made figuring this out really hard), the first run goes great. The second run may also go well, or only the first Feature class will get calculated. Similarly for the third run. Eventually neither feature class will get calculated. (Testing with a different expression each run, e.g. "Run1", "Run2").&lt;/P&gt;&lt;P&gt;I am using the same data for each run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current best guess (based on some experimenting) is that later in the script I delete the field that's being calculated, and that's what's causing it to freak out. Does anyone have any ideas for how to prevent that from happening?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 22:42:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176150#M64609</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-05-20T22:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176162#M64610</link>
      <description>&lt;P&gt;If it's running differently on each pass, the problem is obviously somewhere in script that isn't posted.&lt;/P&gt;&lt;P&gt;Mention scripting tool, Pro, parameters, and such.&amp;nbsp; sounds almost like a model, which changes everything with &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/nesting-models-in-model-builder-running-two/m-p/1172875#M55048" target="_self"&gt;iterating&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;If the script is passing the proper path/featureclass to the calculate tool, it should be calculating the values.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I'm actually watching it create the field it needs in each FC if it isn't already there, so it's definitely working on the right things.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Why not move the calculate field directly below the add field, and do it in one iteration.&lt;/P&gt;&lt;P&gt;Often it is easier to hard code the path in the tool, instead of a value passed from a variable/parameter.&lt;/P&gt;&lt;P&gt;Then, once it is working and not "freaking out", go back in and change to the parameter/variable substitution, and it will often make the issue more obvious.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2022 00:09:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176162#M64610</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-05-21T00:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176163#M64611</link>
      <description>&lt;P&gt;Yes, at this point I am pretty sure that it is something about the field being deleted that is causing the issue; when I comment that out, it's fine, then the issue occurs on the next run immediately after uncommenting it. I have edited my original post, and mentioned this in my last comment.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I'm actually watching it create the field it needs in each FC if it isn't already there, so it's definitely working on the right things.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Why not move the calculate field directly below the add field, and do it in one iteration.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This is what I mean (from the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;Calculate Field Documentation page&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;If a field with the specified name does not exist in the input table, it will be added.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It's all being done in the same iteration. &lt;SPAN&gt;The tool is supposed to add a field, calculate it, and then delete it at the end because the field is not needed any longer. it seems that the deletion is causing issues.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The script &lt;STRONG&gt;is&lt;/STRONG&gt; working on the right feature classes; I can tell because it's creating fields when trying to calculate them. Like I said, something about that field being deleted at the end of the tool causes the next run to be messed up.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To reiterate, with DeleteField() active at the end of the script, the Field Calculation will either not calculate at all or calculate the field as Null, with the exception of the first feature class in the list, which is fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This behavior begins as soon as DeleteField() is active, and can only be fixed by turning it off and restarting Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you are wondering why I keep running this on the same set of data over and over, it's for testing purposes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2022 00:29:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1176163#M64611</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-05-21T00:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178157#M64655</link>
      <description>&lt;P&gt;I’d throw in that it could be a possible dataset caching issue with Pro. It’s caching has caused odd results in several of my scripts, as well as others that I have helped troubleshoot for work. I close/ reopen Pro and the attributes are different. ‘Refresh’ or disconnecting from the database doesn’t work unfortunately. It got really bad one time and had mapped attributes from one featureclass to a different one, duplicating all of its fields with _1. Other datasets were ‘empty’, but get count returned with 45k results. &amp;nbsp;Hopefully they can get the caching working properly.&lt;/P&gt;</description>
      <pubDate>Sat, 28 May 2022 04:06:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178157#M64655</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-05-28T04:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178719#M64677</link>
      <description>&lt;P&gt;This is a good point. I was wondering if anyone had a way to clear the cache without closing Pro?&lt;/P&gt;&lt;P&gt;Edit: through scripting, not just going into Options.&lt;/P&gt;&lt;P&gt;Edit 2: Options&amp;gt; Clear Cache does not fix the problem.&lt;/P&gt;&lt;P&gt;It looks like&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/clear-workspace-cache.htm" target="_blank" rel="noopener"&gt;Clear Workspace Cache (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;only works for Enterprise GDBs.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 18:39:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178719#M64677</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-05-31T18:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178745#M64678</link>
      <description>&lt;P&gt;To refresh the data, try switching the table of contents to list by data source, right click on the geodatabase, choose refresh.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 19:21:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1178745#M64678</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-05-31T19:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working when iterating through a list of feature classes</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1180392#M64713</link>
      <description>&lt;P&gt;As it turns out, that is only available in Enterprise GDBs, and refreshing the map, the GDB in Catalog, and the Tables, don't do anything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I might have to chalk this up to an error. Not sure if to report it as a bug or request it as an Idea.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:38:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-when-iterating-through/m-p/1180392#M64713</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-06-06T19:38:05Z</dc:date>
    </item>
  </channel>
</rss>

