<?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 Custom tool validation inside model builder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/custom-tool-validation-inside-model-builder/m-p/29806#M2316</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a custom tool built on a python script that has some code in initializeParameters in the ToolValidator. The code executes fine when I launch the tool, but if I add that custom tool to a model then the tool validation no longer seems to execute when I run the model. The code is population drop-down lists in the tool and I want those lists to be refreshable, but it looks like in order to make that happen I have to delete the tool from the model and re-add it; otherwise, the lists remain static.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The validation actually uses a python shelve to read in a list of values&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in ToolValidation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def initializeParameters(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; import shelve&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; db = shelve.open(r"c:\mydata\lists")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; list1 = db[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I alter that validation code to try to change the list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def initializeParameters(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = ["My", "New", "List"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I run the tool with this new validation code, it opens with the list updated correctly. But if I run the model that the tool was originally embedded in, it displays the old list--as if the validation code had not executed within the model. If I delete the tool from the model and re-add it, then it runs properly with the updated list. So it seems that ToolValidation does not run within a model for a custom script tool but instead the tools parameter values are static based on whatever values they had when the tool was originally added into the model.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Apr 2013 16:14:06 GMT</pubDate>
    <dc:creator>DonKatnik</dc:creator>
    <dc:date>2013-04-10T16:14:06Z</dc:date>
    <item>
      <title>Custom tool validation inside model builder</title>
      <link>https://community.esri.com/t5/python-questions/custom-tool-validation-inside-model-builder/m-p/29806#M2316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a custom tool built on a python script that has some code in initializeParameters in the ToolValidator. The code executes fine when I launch the tool, but if I add that custom tool to a model then the tool validation no longer seems to execute when I run the model. The code is population drop-down lists in the tool and I want those lists to be refreshable, but it looks like in order to make that happen I have to delete the tool from the model and re-add it; otherwise, the lists remain static.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The validation actually uses a python shelve to read in a list of values&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in ToolValidation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def initializeParameters(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; import shelve&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; db = shelve.open(r"c:\mydata\lists")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; list1 = db[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I alter that validation code to try to change the list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def initializeParameters(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = ["My", "New", "List"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I run the tool with this new validation code, it opens with the list updated correctly. But if I run the model that the tool was originally embedded in, it displays the old list--as if the validation code had not executed within the model. If I delete the tool from the model and re-add it, then it runs properly with the updated list. So it seems that ToolValidation does not run within a model for a custom script tool but instead the tools parameter values are static based on whatever values they had when the tool was originally added into the model.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 16:14:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-tool-validation-inside-model-builder/m-p/29806#M2316</guid>
      <dc:creator>DonKatnik</dc:creator>
      <dc:date>2013-04-10T16:14:06Z</dc:date>
    </item>
  </channel>
</rss>

