AnsweredAssumed Answered

Definition query multiple values

Question asked by aimong on Dec 17, 2014
Latest reply on Dec 22, 2014 by xander_bakker

Hi. I want to create a script tool that let's the user select one or more Line ID and set a definition query and I want to choose from a list based on the Line ID field in the feature class (SetParameter?). How can I do that? Not sure if I need to append to a list and if an expression can grow or shrink depending on how many values are selected.

 

e.g.  LineID = '0001' OR LineID = '0002'..................................

 

Here is the simple (single value) version:

 

import arcpy
Line_ID = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
layer = arcpy.mapping.ListLayers(mxd, "Lines")[0]
sc = set(r[0] for r in arcpy.da.SearchCursor(layer, "LID"))
for s in sc:
    where_clause = "LID = '"+Line_ID+"'"
    layer.definitionQuery = where_clause
    ext = layer.getExtent()
    df.extent = ext
del mxd, df, layer, sc, s

Outcomes