import arcpy arcpy.env.overwriteOutput = True mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "Taxparcels")[0] #Define input/output input = arcpy.GetParameterAsText(0) fieldName = arcpy.GetParameterAsText(1) values = arcpy.GetParameterAsText(2) output = arcpy.GetParameterAsText(3) #Build the where clause queryJoin = "' OR " + fieldName + " = '" whereClause = fieldName + " = '" + queryJoin.join(values) + "'" #Select(input, output, whereClause) arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause) if int(arcpy.GetCount_management("Taxparcels").getOutput(0)) > 0: arcpy.Select_analysis("Taxparcels", output)
Solved! Go to Solution.
#Build the where clause whereClause = "{0} in ('{1}')".format(fieldName, "','".join(values.split(';')))
#Build the where clause values = values.split(";") # split values into list values = ["'{0}'".format(v) for v in values] # add single quotes whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
query = 'field = x or field = y or field = z' #etc
query = 'field in (x, y, z)'
#Build the where clause whereClause = "{0} in ('{1}')".format(fieldName, "','".join(values.split(';'))) #Select(input, output, whereClause) if int(arcpy.GetCount_management(lyr).getOutput(0)) > 0: arcpy.Select_analysis(lyr, output, whereClause)
#Build the where clause whereClause = "{0} in ('{1}')".format(fieldName, "','".join(values.split(';')))
#Build the where clause values = values.split(";") # split values into list values = ["'{0}'".format(v) for v in values] # add single quotes whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))