1

I have 3 parameters in my tool, including para0, para1, para2. These parameters will be the user's inputs. I would like to display a message box if para0>para1 or para1>para2 or para2>para3.

My script in Tool Validation shows the message box every time when one parameter is filled. However, I would like the message box should appear only once when all parameters has been filled.

import arcpy, pythonaddins
class ToolValidator(object):

 def updateParameters(self):
   if (self.params[0].value is not None) and (self.params[1].value is not None) and (self.params[1].value<self.params[0].value):
       pythonaddins.MessageBox('WARNING: Degree 2 must be larger than degree 1', 'WARNING',0)
   elif  self.params[1].value is not None and self.params[2].value is None:
        pass
   elif self.params[1].value is not None and self.params[2].value is not None and self.params[2].value<self.params[1].value:
        pythonaddins.MessageBox('WARNING: Degree 3 must be larger than degree 2', 'WARNING',0)
   elif  self.params[2].value is not None and self.params[3].value is None:
         pass
   elif self.params[2].value is not None and self.params[3].value is not None and self.params[3].value<self.params[2].value:
         pythonaddins.MessageBox('WARNING: Degree 4 must be larger than degree 3', 'WARNING',0)
1
1

The GP tool framework with ToolValidator.updateMessages function let you provide feedback to the user in a way that standard and familiar (some text accompanied by either warning or error icon). The most relevant help topics i'd recommend is this ArcGIS Pro/Customizing script tool behavior

Another reason to avoid the use of message box from ToolValidator (or the execute code for that matter)... is because GP tools are generic objects which may be run in a variety of ways, including : from the tool dialog, in a model (modelbuilder), in a standalone python script, within a gp service. Though the message box may make sense from the tool dialog, if the tool was to be used in the other ways and the message box was displayed it would likely be confusing and the model, script or service would pause and wait for user interaction.

1
  • 1
    Thanks gotchula so much. I tried your suggestions and it works.
    – user30985
    Mar 12 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.