I'm new to ToolValidator for a script tool and I'd like to make two checks which then adds an error if either rule is violated. I need to make sure parameter 2 and 3 (feature classes) are within parameter 1 (feature dataset). The tool will fail (roughly 3/4 of the way through) if the feature classes are not contained in the feature dataset.
Also, the tool needs to display an error is the feature class is empty.
I know Tool Validator is the way to go. I don't have much and am willing to read stuff. Also, this doesn't work, but I've managed to piece it together with some other posts.
import arcpy class ToolValidator(object): """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() def initializeParameters(self): """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" 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.params.value==True: self.params.enabled==True fc=self.params rows = arcpy.SearchCursor(fc) if rows.next(): self.params.enabled==True else: self.params.enabled==False return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return if self.params.hasBeenValidated: self.params.clearMessage() else: self.params.setErrorMessage('Your feature class is empty. 300 Tool will not fail.')