Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Custom tool validation inside model builder

$
0
0
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.

The validation actually uses a python shelve to read in a list of values

in ToolValidation:

def initializeParameters(self):
import shelve
db = shelve.open(r"c:\mydata\lists")
list1 = db[0]
self.params[0].filter.list = list1
return

If I alter that validation code to try to change the list:

def initializeParameters(self):
self.params[0].filter.list = ["My", "New", "List"]
return

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.

Viewing all articles
Browse latest Browse all 2485

Trending Articles