Dynamically define parameters in a python toolbox

565
2
11-04-2019 09:21 AM
Torbjørn_EidsheimBøe
New Contributor II

Is it possible, in a python toolbox, to define a parameter (arcpy.Parameter()) in def updateParameters() or somehow define parameters so that both number (of parameters) and values (in parameter) is dependent on user input in first parameter?

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Not sure about the number of parameters but parameter values can be changed using 'altered'

Customizing tool behavior in a Python toolbox—Geoprocessing and Python | ArcGIS Desktop 

0 Kudos
Torbjørn_EidsheimBøe
New Contributor II

Thanks for reaching out. 

I tried defining all paramters "statically" in def getParameterInfo, but setting enabled=False to the ones i do not want to show up. Then in def updateParameters i tried to set enabled = True, and displayName = 'New_name' (displayName will be dependent on the data the user chooses). Only setting enabled = True works. Trying to change displayName in this way gives an AttributeError. Being able to change displayName would help avoid defining a lot of different parameters in getParameterInfo i think.

Something like this in updateParameters:

if parameters[2].valueAsText:
   parameters[3].enabled = True
   parameters[3].displayName = 'New_name'

Obviously not the way to do it. Not sure I understand how to use 'altered' in this case. Any pointers?

 

0 Kudos