I have a map document with about 10 layers that I would like to create a query definition script tool to use that takes a user input as a parameter and then executes the tool. The script looks like this:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
field = 'Circuit'
value = 
queryStr = str(field) + "=" + str(value) 

for lyr in arcpy.mapping.ListLayers(mxd, "", df):
    if lyr.supports("DEFINITIONQUERY"):
        lyr.definitionQuery = queryStr
del mxd

I can't figure out how to configure the script tool to use the value variable as a user input that then gets used in the definition query. Is this possible?

  • 1
    Post your script toot configuration. I do not see your get/setparameterAsText in the script either. Check the documentation on creating script tools... Apr 12, 2018 at 20:48
  • Another way to get some ideas on Get/SetParameterAsText() is by reviewing these Q&As: gis.stackexchange.com/questions/tagged/…
    – PolyGeo
    Apr 12, 2018 at 23:14


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.