I have a Geoprocessing Script Tool that auto-populates parameters via the initalizeParameters function of the ToolValidator class. This works well when the Tool is run from the toolbox.
Code:
def initializeParameters(self):
# Customize parameter properties.
# This gets called when the tool is opened.
parcels = ['test1','test2']
valueTable = arcpy.ValueTable(len(parcels))
valueTable.setColumns(["GPString","GPDouble"])
for parcel in parcels:
valueTable.addRow([parcel, None])
self.params[0].value = valueTable
Tool Display when open from Toolbox:
This does not run as expected when using Tasks. Task Display:
Only the first item in the parcels list is loaded. There are no errors reported. Does anyone have any suggestions or workarounds? I am using Pro 3.1.0.
Thanks
Solved! Go to Solution.
When making changes to the validation code, specifically modifying the initializeParameters function, you need to reload the Geoprocessing Tool to get code changes recognized. Who Knew.
If you find yourself in this predicament reload the tool or check/uncheck embed in the Task Designer.
I thought that maybe removing the for loop might help. This was substituted using the loadFromString function. It had the same result: the task only displays one of the values.
valueTable.loadFromString(';'.join([f"'{i}' 'None'" for i in parcels]))
I have also tried loading different values for the Acres column under the theory that loading None is a problem. ('1' , '1.1', '1.0')
Instead of populating the value table i've attempted to set a filter on a column of the VT. This also results in the same issue. The VT is missing when the script tool is run from Tasks. Something is off related to the initalizeParameters in Validation.
When making changes to the validation code, specifically modifying the initializeParameters function, you need to reload the Geoprocessing Tool to get code changes recognized. Who Knew.
If you find yourself in this predicament reload the tool or check/uncheck embed in the Task Designer.