Select to view content in your preferred language

SQL drop down list using python toolbox parameters

411
2
Jump to solution
09-03-2024 01:33 PM
ZoeTysonLID1989
Emerging Contributor

Hello, 

I am trying to create a python tool using the python toolbox in ArcPro, I am attempting to automate a process where users select a grid size and a trap number to move the selected grid polygon over the selected trap point. The grid and trap number come from two separate fields in the attribute table. There are hundreds of choices for each selection.

The process works great except, when the tool opens in ArcPro I need two SQL expressions to show up to select the grid and trap number respectively. I can get the parameters to appear looking like SQL expressions when the tool opens (see image) but there are no value options available in the drop down. I know this is likely because I have not defined where they should be retrieving values from, but I am unsure how to do that or make the values populate. Any help would be greatly appreciated!!

0 Kudos
1 Solution

Accepted Solutions
MobiusSnake
MVP Regular Contributor

So I think you'll need to include two parameters for your two data sources, your grids and traps.  You can set a default value for them like this:

 

ds1_param = arcpy.Parameter(
    displayName="Data Source 1",
    name="data_source_1",
    datatype="DEFeatureClass",
    parameterType="Required",
    direction="Input"
)
ds1_param.value = r"C:\Data\your_geodatabase.gdb\Grid"

 

 

Once you have a parameter pointing to your data source, you can use the "parameterDependencies" property on your SQL Expression parameter to link that parameter to your data source:

 

sql1_param = arcpy.Parameter(
    displayName="SQL 1",
    name="sql_1",
    datatype="GPSQLExpression",
    parameterType="Required",
    direction="Input"
)
sql1_param.parameterDependencies = [ds1_param.name]

 

 

There might be a way to set the parameterDependencies property without first creating the feature class parameter, but if not, this should work for you.

View solution in original post

0 Kudos
2 Replies
MobiusSnake
MVP Regular Contributor

So I think you'll need to include two parameters for your two data sources, your grids and traps.  You can set a default value for them like this:

 

ds1_param = arcpy.Parameter(
    displayName="Data Source 1",
    name="data_source_1",
    datatype="DEFeatureClass",
    parameterType="Required",
    direction="Input"
)
ds1_param.value = r"C:\Data\your_geodatabase.gdb\Grid"

 

 

Once you have a parameter pointing to your data source, you can use the "parameterDependencies" property on your SQL Expression parameter to link that parameter to your data source:

 

sql1_param = arcpy.Parameter(
    displayName="SQL 1",
    name="sql_1",
    datatype="GPSQLExpression",
    parameterType="Required",
    direction="Input"
)
sql1_param.parameterDependencies = [ds1_param.name]

 

 

There might be a way to set the parameterDependencies property without first creating the feature class parameter, but if not, this should work for you.

0 Kudos
ZoeTysonLID1989
Emerging Contributor

Sorry for the very late reply, but this worked with a few modifications! Thank you!

0 Kudos