Tool Validator script not working

190
3
02-06-2012 08:52 AM
AmyMeehan
New Contributor
I am trying to write a script in the Tool Validator so that the user can choose one of three options in the first parameter, and based on the user's choice, the other 3 parameters are either enabled or disabled.  However, I cannot seem to get it to work properly.  Nothing happens in the tool when I change the first parameter.  My other 3 parameters are feature sets.  The "Add Records Interactively" part is greyed out while the "Use records from" is enabled in all of them.  My script is below:

class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    import arcpy
    self.params = arcpy.GetParameterInfo()
    print self.params

  def initializeParameters(self):
    self.params[1].category = "Feature Types"
    self.params[2].category = "Feature Types"
    self.params[3].category = "Feature Types"
        
    
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return

  def updateParameters(self):
    if self.params[0].altered:
      if self.params[0].value == "Point":
        self.params[1].enabled = 1
        self.params[2].enabled = 0
        self.params[3].enabled = 0
      elif self.params[0].value == "Line":
        self.params[1].enabled = 0
        self.params[2].enabled = 1
        self.params[3].enabled = 0
      elif self.params[0].value == "Polygon":
        self.params[1].enabled = 0
        self.params[2].enabled = 0
        self.params[3].enabled = 1

      """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return


What am I doing wrong?  I'm completely stumped!

Thank you in advance for any help!

Amy
0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor
What am I doing wrong?  I'm completely stumped!


I tried your script and got the same results, though for another, similar type (Feature Layer) your logic worked perfectly. My guess is this is not supported for feature set parameters because of their special ability to interact with the hosting application.
0 Kudos
AmyMeehan
New Contributor
Ugh.  Not what I wanted to hear!  But thank you for testing it and for your reply!!

Amy
0 Kudos
FatihDur
New Contributor II
I have been doing some research on the same topic, about categorising the parameters on the script tool dialog, and came across your message. I have tried your code in v.10 and it worked just fine. I think the problem was defining the right data datatype for your parameters. Here is the details:
- In the source .py file there are 4 params set by arcpy.GetParameterByText(x);
- In the script properties' Parameters tab, all parameters are set to String (This makes the difference I reckon);
- Only the first parameter has a Value List filter which contains the values of Point|Polygon|Line (w/o quotation);

When I run it, the script enables the right box among three given. If you are planning to use feature class as the first parameter instead of a string, you need to use Describe tool to access feature class properties in string format.

My problem was whether it is possible to set param.category property outside the getParameterInfo() def and the answer is that it is possible in initializeParameters(self).

Thanks,

Fatih
0 Kudos