import sys, arcpy
arcpy.env.workspace = "C:\Scratch"
Environment_Index = arcpy.GetParameterAsText(0)
Measure = arcpy.GetParameterAsText(1)
if Environment_Index == "Percentage of Environmental Hazard":
if Measure == "0-25%":
Expression = '"per_Envi_H" >0 AND "per_Envi_H" <25'
elif Measure == "25-50%":
Expression = '"per_Envi_H" >25 AND "per_Envi_H" <50'
elif Measure == "50-75%":
Expression = '"per_Envi_H" >50 AND "per_Envi_H" <75'
elif Measure == "75-100%":
Expression = '"per_Envi_H" >75 AND "per_Envi_H" <100'
else:
Expression = "0"
print Expression
arcpy.SetParameter(2, Expression)
elif Environment_Index == "Percentage of Flooded Area":
if Measure == "0-25%":
Expression = '"Per_Flood" > 0 AND "Per_Flood" <25'
elif Measure == "25-50%":
Expression = '"Per_Flood" > 25 AND "Per_Flood" <50'
elif Measure == "50-75%":
Expression = '"Per_Flood" > 50 AND "Per_Flood" <75'
elif Measure == "75-100%":
Expression = '"Per_Flood" > 75 AND "Per_Flood" <100'
else:
Expression = "0"
print Expression
arcpy.SetParameter(2, Expression)
else:
if Measure == "0-50kgs/yr":
Expression = '"pest_kg" >0 AND "pest_kg" <50'
elif Measure == "50-100kgs/yr":
Expression = '"pest_kg" >50 AND "pest_kg" <100'
elif Measure == "100-250kgs/yr":
Expression = '"pest_kg" >100 AND "pest_kg" <250'
elif Measure == "250-500kgs/yr":
Expression = '"pest_kg" >250 AND "pest_kg" <500'
else:
Expression = "0"
print Expression
arcpy.SetParameter(2, Expression)
I am trying to get a string as an output parameter from the script tool and use the string as the expression for the select by attribute tool.
My user wanted to have a range of values to be selected from a field, I thought it was an easy process by writing a python code.
I tried using the set parameter for the output parameter. I don't understand where the problem is.
This is my script tool in the model builder
{}
button instead of attaching a picture? It makes it easier to review and test the code.