Is there a way to retain Warning or Error messages for parameters between tool validation calls?
In my example below, I want to check the input feature class for something, and add a warning message. For efficiency, I only want to perform these checks and update the messages IF that parameter has changed. But then if I change a different parameter (like unchecking the box in my example), it removes all existing messages.
I have several checks to perform and it takes a few seconds, so I don't want to run these checks every time a subsequent, unrelated parameter is updated. It would be much faster if there was a way to see:
Is there already a warning message here? If so, keep it.
The .hasWarning() property doesn't tell me what the message itself is.
class msgtest(object):
def __init__(self):
self.label = "Message test"
self.description = "Message Test"
self.canRunInBackground = False
def getParameterInfo(self):
in_fc = arcpy.Parameter(
displayName="Input feature class",
name="in_fc",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
checkbox = arcpy.Parameter(
displayName="Checkbox",
name="checkbox",
datatype="GPBoolean",
parameterType="Required",
direction="Input")
checkbox.value = True
parameters = [in_fc,checkbox]
return parameters
def updateMessages(self, parameters):
# Example - Throw warning message if less than 100 features
# this option only runs when the input FC has been updated. Messages will disappear if a different parameter is changed.
if (parameters[0].altered and not parameters[0].hasBeenValidated):
if int(arcpy.GetCount_management(parameters[0].value).getOutput(0)) < 100:
parameters[0].setWarningMessage('Fewer than 100 items')
# this option runs every time. Message will always appear correctly but is very inefficient
#if parameters[0].value:
# if int(arcpy.GetCount_management(parameters[0].value).getOutput(0)) < 100:
# parameters[0].setWarningMessage('Fewer than 100 items')
return
def execute(self, parameters, messages):
return