<?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: How to create python Tool that maintains input-derived state between runs in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400094#M80874</link>
    <description>&lt;P&gt;Thanks for the guidance! I was also thinking about somehow loading parameters from a file but figured there must be a more graceful solution (it would seem there isn't!). Using the project filepath seems like a good way to go for a stable location.&lt;/P&gt;</description>
    <pubDate>Sun, 24 Mar 2024 16:19:07 GMT</pubDate>
    <dc:creator>sbrowneotogo</dc:creator>
    <dc:date>2024-03-24T16:19:07Z</dc:date>
    <item>
      <title>How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400015#M80851</link>
      <description>&lt;P&gt;Hello ESRI community, I'm a python developer who's new to ArcGIS Pro and trying to get started on developing a tool. I read through a bunch of documentation and resources but still struggling to sketch out an architecture for what I'm trying to achieve and I'm hoping a veteran can point me in the right direction!&lt;/P&gt;&lt;P&gt;Here's the outline of what I'm trying to build, and I'm happy to provide more detail or context as required:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For 1 or more variables, take as user input a series of thresholds that define categories. For instance, it might look like this:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="python"&gt;rules=[ 
    {'min_val':0, 'max_val':10, 'cat':'Low'}, 
    {'min_val':10, 'max_val':25, 'cat':'Medium'}, 
    {'min_val':25, 'max_val':100, 'cat':'High'} 
]&lt;/LI-CODE&gt;&lt;P&gt;where the min_val and max_val determine a category (values between 0 and 10 are 'Low' etc)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;This would be displayed to the user with default values that they can modify.&lt;/LI&gt;&lt;LI&gt;The user would select a variable from a list of options, modify the values, and then select a different variable and modify that one as well.&lt;/LI&gt;&lt;LI&gt;When they're done changing thresholds, I would run some processing using the thresholds.&lt;/LI&gt;&lt;LI&gt;Here's the tricky part: after running the tool, I want them to be able to pull up the tool again &lt;EM&gt;&lt;EM&gt;&lt;EM&gt;with the previously selected thresholds as the defaults.&lt;/EM&gt;&lt;/EM&gt;&lt;/EM&gt;&lt;P&gt;I see how to set default values in a python Toolbox, but I'm wondering how (and whether) it's possible to dynamically set defaults based on previous runs.&lt;/P&gt;&lt;P&gt;Thanks to anyone who can provide pointers!&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Sat, 23 Mar 2024 19:43:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400015#M80851</guid>
      <dc:creator>sbrowneotogo</dc:creator>
      <dc:date>2024-03-23T19:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400028#M80855</link>
      <description>&lt;P&gt;Ha! You've discovered the stateless nature of GP Tools.&amp;nbsp; It can be infuriating.&amp;nbsp; Three thoughts:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The GP History pane stores the state of a tool.&amp;nbsp; Each time the user runs your tool it'll show up in the History pane with its state.&amp;nbsp; For subsequent runs, they would open the tool from the history pane and it will open with the last parameters they used.&amp;nbsp; I use the History pane A LOT.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;Run the tool within ModelBuilder.&amp;nbsp; Of course this requires your user to know ModelBuilder, but it acts much the same was as the History pane in that it remembers the state of the tool.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;The last idea involves storing state in a file and opening/reading the file in your tools' updateParameters() method (Python toolbox) and initializeParameters() method (script tool).&amp;nbsp;&amp;nbsp;Although it's discouraged, you can open/manipulate files as long as it doesn't affect performance.&amp;nbsp;For simplicity, let's say there's only one state-keeping file for a project - that is, you don't allow the user to create and choose multiple state-keeping files.&amp;nbsp; For this you need a known stable location to create/write/read the file.&amp;nbsp; This ought to work:&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;location = aprx.homeFolder&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I did something like this years ago in desktop.&lt;/P&gt;&lt;P&gt;You could get fancier by allowing the user to choose multiple state-keeping files.&amp;nbsp; This would require a new tool parameter to list the files and a catalog (such as a folder) to store the multiple files.&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Tool Validation topics:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-script-tool-behavior.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-script-tool-behavior.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-tool-behavior-in-a-python-toolbox.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-tool-behavior-in-a-python-toolbox.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 16:19:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400028#M80855</guid>
      <dc:creator>Dale_Honeycutt</dc:creator>
      <dc:date>2024-03-24T16:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400094#M80874</link>
      <description>&lt;P&gt;Thanks for the guidance! I was also thinking about somehow loading parameters from a file but figured there must be a more graceful solution (it would seem there isn't!). Using the project filepath seems like a good way to go for a stable location.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 16:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400094#M80874</guid>
      <dc:creator>sbrowneotogo</dc:creator>
      <dc:date>2024-03-24T16:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400101#M80875</link>
      <description>&lt;P&gt;In scanning the doc, I found there are some caveats to the project directory&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The user needs to save the project first, otherwise it goes to some default home location that'll be lost when they save for the first time&lt;/LI&gt;&lt;LI&gt;Then there's this:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dale_Honeycutt_0-1711298608452.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/98925iF1BFDD62A1D50148/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dale_Honeycutt_0-1711298608452.png" alt="Dale_Honeycutt_0-1711298608452.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Seems like filePath is a better option than homeFolder&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 16:47:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400101#M80875</guid>
      <dc:creator>Dale_Honeycutt</dc:creator>
      <dc:date>2024-03-24T16:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400117#M80877</link>
      <description>&lt;P&gt;The aprx.filePath seems to return a path to an actual file like this (at least when working in an environment with an already saved project):&lt;BR /&gt;&lt;BR /&gt;'C:\\test_project\\test_project.aprx'&lt;/P&gt;&lt;P&gt;whereas aprx.homeFolder returns an actual directory:&lt;/P&gt;&lt;P&gt;'C:\\test_project'&lt;/P&gt;&lt;P&gt;so I'm not sure how to use filePath - maybe just go up one level from the file itself to get its parent directory?&lt;/P&gt;&lt;P&gt;I have some logic to detect if the the parameter file exists, and if it doesn't I create it with default values, so if the user's effective homeFolder changes and they lose their current parameters, (for my purposes at least) it's not a big deal to start over again once with default values.&lt;/P&gt;&lt;P&gt;The potential homeFolder lock is a little more concerning - I'm just creating this tool for my own team, and I'm not anticipating releasing to a wider audience, but if I ever do I'll have to account for that. Very much appreciate the heads up!&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 18:02:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400117#M80877</guid>
      <dc:creator>sbrowneotogo</dc:creator>
      <dc:date>2024-03-24T18:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create python Tool that maintains input-derived state between runs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400139#M80878</link>
      <description>&lt;P&gt;You could import Python's os.path module -- it has tons of methods for busting apart and constructing pathnames.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 19:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-create-python-tool-that-maintains-input/m-p/1400139#M80878</guid>
      <dc:creator>Dale_Honeycutt</dc:creator>
      <dc:date>2024-03-24T19:29:56Z</dc:date>
    </item>
  </channel>
</rss>

