AnsweredAssumed Answered

Validator error with lists and set values

Question asked by IMakeNiceMaps on Nov 21, 2019
Latest reply on Nov 25, 2019 by IMakeNiceMaps

I have some simple ArcPy script tool validator code that is giving me grief. I am using desktop at 10.3.1. I'm open to whatever help can be offered to get this to work as intended.


I have two parameters for my script tool. The first is the type of product to be created, the second is the scale of the product. Digital Map / No scale required are the default values defined in the Tool Validator code.


If it is a paper product, the user selects the appropriate scale from the drop-down list. The problem I can't solve is that if the user changes the value in parameter 0 to paper map, the list of scales becomes available but the value is still the default ("No scale required") so an error is thrown because that option is not in the scale list. The error clears when I select the scale from the list, but I want only those choices available and obviously don't want the error to appear at all.


Likewise if I then change parameter 0 back to Digital Map the "No scale required" value appears but the error message is thrown again because that value is not in the scale list, which is somehow still appearing. There is no way to clear the error at this point.


I'd really appreciate help with how to get these different combinations to appear and change as intended without any errors. If they pick Paper, only the scales appear. If they switch back to Digital, only the "No scale required" value appears. And so on. I can't guarantee the user's behaviour so I'd like for it to be bulletproof.


import arcpy
class ToolValidator(object):

  def __init__(self):
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    # Define the list of product types the user can choose from
    self.params[0].filter.list = ["Digital Map", "Paper Map"]
    self.params[0].value = "Digital Map" 

  def updateParameters(self):
    if self.params[0].value == "Digital Map":
        self.params[1].value = "No scale required"               
    if self.params[0].value == "Paper Map":
        self.params[1].filter.list = ["1:10,000", "1:25,000"]

  def updateMessages(self):