Python toolbox parameter validation / error message problem

1601
2
10-18-2011 04:13 AM
MarkCorbin
New Contributor III
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
Tags (2)
0 Kudos
2 Replies
DavidWynne
Esri Contributor
Hi Szymon,
You're hitting a bug, that should work.  I'll provide a NIM # a little bit later.

Alternatively, you can accomplish the same thing with one line by setting a filter list on the parameter within getParameterInfo.  Something equivalent to this:

param0.filter.list = ["Polygon"]


That will trigger some automatic validation without you having to set up something equivalent.

-Dave
0 Kudos
DavidWynne
Esri Contributor
I'll provide a NIM # a little bit later.


For your reference: NIM074188
0 Kudos