Dynamically populate input fields in python toolbox

1080
2
Jump to solution
04-13-2024 08:34 AM
sbrowneotogo
Emerging Contributor

Hello ESRI community,

I'm working on a python toolbox that will have many variables that the user can change. I'm trying to find a way to do this without having dozens of parameters in my arcpy toolbox, which will make maintenance of this tool an absolute nightmare.

 

To give a quick summary, I have several categories, and within each category there maybe be 6 to 10 variables that the user can change. The way I structured the tool is to save a JSON for each category (this also allows me to save state between runs).

 

Within getParameters, the user chooses a category from a dropdown list:

 

var_name = arcpy.Parameter(
displayName="Variable Name",
name="var_name",
datatype="GPString",
parameterType="Required",
direction="Input")
var_name.filter.list = ["Category1", "Category2", "Category3", "Category4"]

 

and for each of these categories, there's another parameter which contains the JSON:

category1 = arcpy.Parameter(
displayName="Category 1",
name="category1 ",
datatype="GPString",
parameterType="Required",
direction="Input")
category1.enabled = 0

 

This is always disabled, and the user doesn't see it. It contains a string of a JSON that might looks like this:

{'var1': 10, 'var2' :20, 'var3': 30, 'var4': 40, 'var5': 50, 'var6': 60, 'var7': 70, 'var8': 80}

Then I'll have a parameter for each of these vars, which is enabled and populated from the parsed JSON when the relevant category is chosen and disabled otherwise. As you can tell by doing some simple math, this will result in 50+ parameters (yikes). My plan was to have 8 parameters that simply get recycled between categories, but that was foiled when I discovered you can't change the displayName property in updateParameters.

 

Is there a way to structure this tool so users can modify the many variables without having so many parameters? I'm not sure if the question was clear enough, I'm happy to clarify if helpful.

0 Kudos
1 Solution

Accepted Solutions
Dale_Honeycutt
Frequent Contributor

 

Take a look at using a Value Table parameter.  

 

View solution in original post

2 Replies
Dale_Honeycutt
Frequent Contributor

 

Take a look at using a Value Table parameter.  

 

sbrowneotogo
Emerging Contributor

I see GPValueTable is listed as a datatype for parameters so this might be the answer! Will give a try, thanks for the tip

0 Kudos