I have been developing a Python toolbox which consists of 6 parameters. I have received immense amounts of help on this through StackExchange through the following posts:
I must say, you guys rock! I'm getting close to finishing up this toolbox and have yet again hit another wall.
For one of my parameters, I would like to throw a warning to the user if it is not a point shapefile. The main purpose of this tool is to label point shapefiles, so if they enter a polygon, that's going to potentially be a whole lot of labels showing on one map (at least for polygon shapefiles that I deal with). For some reason, the only way for the warning to appear correctly is for my updateParameters and updateMessages functions to consist of the following:
def updateParameters(self, parameters): describe = arcpy.Describe(parameters.value) if describe.shapeType not in ('Point', 'Multipoint)': parameters.setWarningMessage('This is not a point feature class') else: parameters.clearMessage() if parameters.value == True: parameters.enabled = True parameters.enabled = True parameters.enabled = True else: parameters.enabled = False parameters.enabled = False parameters.enabled = False return def updateMessages(self, parameters): if parameters != None: describe = arcpy.Describe(parameters.value) if describe.shapeType not in ('Point', 'Multipoint'): parameters.setWarningMessage('This is not a point shapefile. Labeling is not recommended.') else: parameters.clearMessage() return
I can feed in a polygon shapefile and the warning appears and everything runs as it should. However, if I comment out the first 5 lines of the updateParameters method (the portion that checks if its a point and which also appears to be redundant), then my toolbox initially appears to have a bunch of errors with it once I open it:
My guess is that this has something to do with the order of validation that is performed for the tool. However, once I feed in a shapefile into the tool, all of the errors go away and the tool runs fine. So I have my tool working, just not in the way that I want it to since (a) I don't want to include a piece of code that I feel is redundant and (b) I shouldn't have error flags all over the place with the initial state of my tool.