Geographic Information Systems Asked on July 30, 2021
I’m working on a Python toolbox that buffers features using slope distance based on an input DEM rather than horizontal distance. The tool works great with buffer widths derived from a field in the input feature.
I’d like to add the option to buffer by one given width like the ArcGIS proximity tool, Buffer, resulting in a radio button choice:
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.
Correct answer by Ian Yau on July 30, 2021
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
Answered by maverickGIS on July 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP