Writing Python toolbox that gives two options for one parameter?
I use a checkbox and then a conditional statement on the existence of the moveTapToBP variable to achieve a similar logic split.
param2 = arcpy.Parameter(
displayName = "Move un-snapped taps to their building points",
name = "moveTapToBP",
datatype = "GPBoolean",
parameterType = "Required",
direction = "Input")
param2.value = False
I got to where I wanted to go using the updateParameters and updateMessages functions:
def updateParameters(self, parameters):
if parameters[0].altered:
if parameters[0].value:
parameters[1].enabled = False
else:
parameters[1].enabled = True
if parameters[1].altered:
if parameters[1].value:
parameters[0].enabled = False
else:
parameters[0].enabled = True
return
def updateMessages(self, parameters):
if not parameters[1].value and not parameters[2].value:
parameters[1].setErrorMessage(
'''Either parameter 1 OR parameter 2 must be supplied, but not both.''')
parameters[2].setErrorMessage(
'''Either parameter 1 OR parameter 2 must be supplied, but not both.''')
elif parameters[1].value and parameters[2].value:
parameters[1].setErrorMessage(
'''Either parameter 1 OR parameter 2 must be supplied, but not both.''')
parameters[2].setErrorMessage(
'''Either parameter 1 OR parameter 2 must be supplied, but not both.''')
return
When the tool loads, the parameters appear as though required, with the green dot:
If both parameters are populated, then it becomes a red error X with the error message:
The updateParameters function disables the other parameter once one parameter is populated.