Tool validator - required field starts as error

743
4
01-20-2011 09:15 AM
SteveSalas
Occasional Contributor
I am building a tool where the two required inputs are, in order, a geodatabase, and a domain name.  When I attempt a validator to create the list of domain names after the geodatabase is selected, the tool always opens with the geodatabase as an error (because it is a required parameter and not yet populated).  Is it possible to have it just show the green dot as a required input when the tool is first opened, rather than the red-X error?  I was under the impression the the updateParameters block was only executed after the interface is interacted with by the user.  Instead it seems to run this code as the tool is opened:

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    desc = arcpy.Describe(self.params[0].value)
    domList = desc.Domains
    domList.sort()
    self.params[1].filter.list = domList
    return


If I click on the red-X, it shows:  ERROR updateParameters Execution Error: Runtime error : # does not exist

Thanks for any assistance.
0 Kudos
4 Replies
LoganPugh
Occasional Contributor III
I think updateParameters also runs when the tool is opened. Try conditionally executing your current code only if the first parameter has been altered:

def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].altered:
        desc = arcpy.Describe(self.params[0].value)
        domList = desc.Domains
        domList.sort()
        self.params[1].filter.list = domList
    return
0 Kudos
SteveSalas
Occasional Contributor
Many thanks!  I saw that "altered" property in the help but didn't implement it properly.  Much nicer when my tool doesn't immediately throw a large red-X error at the user...
0 Kudos
DaleHoneycutt
Regular Contributor
Actually, what's going on is your parameter doesn't yet have a value.  Test that your parameter has a value before describing it.  You can use the altered state as a test as suggested, but the truest test is that it has a value:

if self.parameters[0].value:
0 Kudos
MelindaMorang1
New Contributor III
Many thanks to all of you.  I had this exact same problem, and the solutions listed here worked perfectly for me.
0 Kudos