curtvprice

ToolValidator code - script tool output type dataset force .dbf extension

Discussion created by curtvprice Champion on Jan 17, 2014
Latest reply on Jan 22, 2014 by curtvprice
I have a tool that takes a table view as input and outputs either a feature class or table, depending on the input. Of course the parameter data type is read only so I can't change that in the ToolValidator class

I set the input data type is "Table View" and the output data type to "Dataset", and this seems to work. The problem I'm having is that the validator always adds a .dbf extension for folder workspaces (the output still makes a shapefile and adds the shapefile feature class to the map).

I can change the path to .shp manually in the tool dialog and that seems to work fine. But I'd like it to go to .shp if the output workspace is a folder and the input is a feature layer.

Here is my validation code:

  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].value and self.params[1].value:
      ds =  self.params[0].value
      if arcpy.Describe(ds).dataType[:5] != "Table":
        out = str(self.params[1].value)
        if os.path.splitext(out)[1] == ".dbf":
          self.params[1].value = os.path.splitext(out)[0] + ".shp"
        # the above change does not "stick" - the internal validation
        # switches it back to .dbf
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    # I needed add this because the default validation
    # was not finding existing data and warning me.
    if self.params[1].value:
      if arcpy.Exists(self.params[1].value):
        self.params[1].setIDMessage("Error",1251)
    return


Screen shot: [ATTACH=CONFIG]30603[/ATTACH]

Attachments

Outcomes