#------------------------------------------------------- # BufferFeeder.py validation code # Feb 2012 msayler # Updated Jul 2012 # Must be copied into the script tool's validation code # in the Validation tab under Properties #------------------------------------------------------- class ToolValidator: """Class for validating a tool's parameter values and controlling the behavior of the tool's dialog.""" def __init__(self): """Setup the Geoprocessor and the list of tool parameters.""" import arcpy self.params = arcpy.GetParameterInfo() self.X = 0 self.fcfield = (None,None) def initializeParameters(self): """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" self.params[1].enabled = False self.params[2].enabled = False #self.params[3].Value = self.X #for debugging return 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.X == 0: if self.params[0].altered == True: FC = str(self.params[0].value) + "\\gis2.ELEC.ElectricDataset\\gis2.ELEC.eCircuitBreaker" Col = "FeederID" self.fcfield = (FC, Col) self.params[1].filter.list = [str(val) for val in \ sorted(\ set(\ row.getValue(Col) for row in \ arcpy.SearchCursor(FC, None, None, Col)\ )\ )\ ] self.params[1].enabled = True self.params[2].enabled = True self.X = 1 #self.params[3].value = self.X #for debugging # if self.params[1].Value not in self.params[1].filter.list: # self.params[1].Value = self.params[1].filter.list[0] return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return
def updateParameters(self, parameters): '''Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.''' #Need to make sure that the additional fields option ONLY lists fields #that will not be standardized. if parameters[0].value: old_fields = [field.name for field in arcpy.ListFields(parameters[0].value)] if parameters[1].altered: if parameters[1].valueAsText in old_fields: old_fields.pop(old_fields.index(parameters[1].valueAsText)) if parameters[2].altered: if parameters[2].valueAsText in old_fields: old_fields.pop(old_fields.index(parameters[2].valueAsText)) parameters[3].filter.list = old_fields