<?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 Python Toolbox with Many AddField() Calls Runs Slower With Attribute Window Open in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1044488#M60699</link>
    <description>&lt;P&gt;I recently finished developing a python toolbox tool that ends up calling the arcpy.AddField_management() function about 25 times or so. I first developed it as a standalone script to get it working before I connected it up to my python toolbox. When I started testing the tool with the exact same data I found that the run time went up from ~20 seconds in standalone to ~80 seconds when run from a python toolbox inside an ArcGIS Pro map, a 4x increase. After playing around some more I found that it was definitely the AddField tool slowing it down, and then I noticed that if I close the attribute table in the Pro map the run time goes down to ~50 seconds.&lt;/P&gt;&lt;P&gt;So what I think is happening is that that the Pro map is busy revalidating locks and updating the GUI, etc. unnecessarily mid-script. I also notice that when the add field tools are called the "Add" and "Calculate" field buttons start alternating being grayed out, like it is cycling through locks and UI updates or something.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="These alternate being gray" style="width: 183px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/10280iFA52FA4D1B8B3154/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2021-04-06 205356.jpg" alt="These alternate being gray" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;These alternate being gray&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Is there any way to prevent this from happening? Can I somehow pause all that validation or whatever it is for the duration of my script? If not, is there a more efficient method to add fields? These short runtimes may not seem like a big deal but I now realize that I have many tools that have a LOT of calls to AddField and this is likely something that happens throughout my toolbox. I would like to make sure my code is as clean and efficient as practical.&lt;/P&gt;&lt;P&gt;All of the feature classes that have the add field function called on are in_memory layers, and are copied to new feature classes for the output layers.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Apr 2021 01:11:05 GMT</pubDate>
    <dc:creator>Justin_P</dc:creator>
    <dc:date>2021-04-07T01:11:05Z</dc:date>
    <item>
      <title>Python Toolbox with Many AddField() Calls Runs Slower With Attribute Window Open</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1044488#M60699</link>
      <description>&lt;P&gt;I recently finished developing a python toolbox tool that ends up calling the arcpy.AddField_management() function about 25 times or so. I first developed it as a standalone script to get it working before I connected it up to my python toolbox. When I started testing the tool with the exact same data I found that the run time went up from ~20 seconds in standalone to ~80 seconds when run from a python toolbox inside an ArcGIS Pro map, a 4x increase. After playing around some more I found that it was definitely the AddField tool slowing it down, and then I noticed that if I close the attribute table in the Pro map the run time goes down to ~50 seconds.&lt;/P&gt;&lt;P&gt;So what I think is happening is that that the Pro map is busy revalidating locks and updating the GUI, etc. unnecessarily mid-script. I also notice that when the add field tools are called the "Add" and "Calculate" field buttons start alternating being grayed out, like it is cycling through locks and UI updates or something.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="These alternate being gray" style="width: 183px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/10280iFA52FA4D1B8B3154/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2021-04-06 205356.jpg" alt="These alternate being gray" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;These alternate being gray&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Is there any way to prevent this from happening? Can I somehow pause all that validation or whatever it is for the duration of my script? If not, is there a more efficient method to add fields? These short runtimes may not seem like a big deal but I now realize that I have many tools that have a LOT of calls to AddField and this is likely something that happens throughout my toolbox. I would like to make sure my code is as clean and efficient as practical.&lt;/P&gt;&lt;P&gt;All of the feature classes that have the add field function called on are in_memory layers, and are copied to new feature classes for the output layers.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 01:11:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1044488#M60699</guid>
      <dc:creator>Justin_P</dc:creator>
      <dc:date>2021-04-07T01:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox with Many AddField() Calls Runs Slower With Attribute Window Open</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1044515#M60700</link>
      <description>&lt;P&gt;use&amp;nbsp;&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/add-fields.htm" target="_blank"&gt;Add Fields (multiple) (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and keep the table closed&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 02:27:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1044515#M60700</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-07T02:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox with Many AddField() Calls Runs Slower With Attribute Window Open</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1045092#M60717</link>
      <description>&lt;P&gt;Thanks, I updated my code to use Add Field&lt;U&gt;&lt;STRONG&gt;s&lt;/STRONG&gt;&lt;/U&gt; instead of Add Field in a bunch of places and it definitely sped it up quite a bit. It is still strange that having the attribute table open slows it down a noticeable amount.&lt;/P&gt;&lt;P&gt;As a note to others, this function is only available in ArcGIS Pro, and &lt;STRONG&gt;the parameter order in AddFields is actually different than the original AddField&lt;/STRONG&gt;, which left with with a cryptic error for quite a while before I realized that.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 15:46:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-with-many-addfield-calls-runs/m-p/1045092#M60717</guid>
      <dc:creator>Justin_P</dc:creator>
      <dc:date>2021-04-08T15:46:26Z</dc:date>
    </item>
  </channel>
</rss>

