AnsweredAssumed Answered

I need some help with python script to create definition query?

Question asked by djsmith22 on Mar 16, 2018
Latest reply on Apr 27, 2018 by djsmith22

I am trying to write a python script that will allow users to input multiple values from one field(up to 10) to create a definition query for those values. I get the script to work for one value but not for multiple.I am currently testing with just two values using the OR but when I run the script I get one value twice in the definition query for example, Color = ('red') OR Color = ('red')Can one of the experts help me out? Thanks. This is what I have so far:

 

import arcpy
#Set to current mxd and dataframe
mxd = arcpy.mapping.MapDocument ('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")
Layer = (mxd,"Test",df)
# Set the tool parameters
InputFeatureclass = 'Test'
InputField = 'Sample'
InputValue = arcpy.GetParameterAsText(0)
InputValue1 = arcpy.GetParameterAsText(1)

Sample= arcpy.mapping.ListLayers(mxd, "Test")[0]
Sample.definitionQuery = """Color = ('{1}') OR Color = ('{1}')""".format(arcpy.AddFieldDelimiters(InputFeatureclass, InputField), InputValue)
arcpy.RefreshActiveView()
mxd.save()

Outcomes