Hello,I am trying add an error message to a Python tool whenever user tries to set as an input parameter a layer with shape type different that Polygon.
def updateMessages(self, parameters):
data = parameters[0].value
desc = arcpy.Describe(data)
shapetype = desc.shapeType.upper()
logger.debug("selected layer's shape type "+shapetype)
if shapetype!='POLYGON':
try:
parameters[0].setErrorMessage (str("Only polygons are allowed"))
errors = parameters[0].hasError()
except Exception, ErrorDesc:
logger.error("There was an error setting error message: "+str(ErrorDesc))
else:
logger.debug("clearing messages")
parameters[0].clearMessage()
return
The problem is that the error message never gets set and what i get in the debug log is:
2011-10-17 13:48:29,171 ERROR There was an error setting error message: ParameterObject: Parameter not valid for SetErrorMessage
According to documentation:
updateMessages is then called. You can examine the warning and error messages that internal validation may have created and modify them or add your own custom warning and error messages.
What makes a parameter valid for SetErrorMessage?I am attaching my sample code.Thanks,Szymon Piskula