Select to view content in your preferred language

Access the "SQL Expression" parameters and add custom filter lists

2104
11
09-21-2023 09:35 AM
xavro
by
Emerging Contributor

Hello, being a beginner on arcpy and in the design of my first script tool in arcgis pro

I want to know if it is possible to access the "SQL Expression" parameters with python and add lists of personalized filters in order to create personal SQL queries.

Thank you very much for your help.

 

0 Kudos
11 Replies
Shauna-RaeBrown
Frequent Contributor

#xavro, here's a link that will get you started. https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/specifying-a-query.htm 

0 Kudos
JeffreyMitzelfelt
New Contributor

A technique I used early on when I was learning about using Python with ArcGIS was to run the tool and, from the Geoprocessing History panel, drag the process to the Python window. This showed me all the parameters that had been used on that run and how they were formatted.

The ultimate source for seeing how the code should be used is the arcpy Python documentation. SearchCursor—ArcGIS Pro | Documentation

xavro
by
Emerging Contributor

Thank you for your answers, but I think we misunderstood or maybe it's me...but the goal is to modify the list of filters available in the "SQL expression" tool. see my screenshot.

xavro_0-1695316112606.png

 

0 Kudos
Shauna-RaeBrown
Frequent Contributor

Here's an earlier post "Programmatically select layer definition query" found here https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definitio... 

See also - "Delete vs deactivate layer definition query"-  https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/13136... 

0 Kudos
AlfredBaldenweck
MVP Regular Contributor
0 Kudos
xavro
by
Emerging Contributor

Thank you, but I know and have already seen everything relating to layer definition requests. The purpose of this tool is to have the possibility of carrying out searches on attributes common to several layers and then defining definition queries on the corresponding layers.

I would like to use initializeParameters(self): to populate my filter lists.
A bit like we can do in a “Chaine” data type via self.params[3].filter.list = category

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

It may be better if you posted some sort of sample code so we can figure out exactly what you're trying for.

I think, though, that you should investigate updateParameters() to change your filter list.

0 Kudos
JohannesLindner
MVP Frequent Contributor

You have to set the dependency of the Sql Expression parameter to a layer/feature class parameter:

JohannesLindner_0-1695320456016.png

 

Then it will grab the possible fields and values from that parameter.

 

Without a selected layer:

JohannesLindner_1-1695320511918.png

 

 

With a selected layer:

JohannesLindner_2-1695320549075.png

 


Have a great day!
Johannes
0 Kudos
xavro
by
Emerging Contributor

Thanks, but is it possible to edit or create these fields/value without feature layer dependencies ?

With updateParameters()  or initializeParameters() ?

0 Kudos