I'm just trying to make it where the user types what county they want and the script selects those features.
import arcpy
County = arcpy.GetParameterAsText(0)
arcpy.env.workspace = (GDB path)
SelectedField = "COUNTY1"
Expression = (SelectedField + '=' + 'County')
arcpy.SelectLayerByAttribute_management("ArmoringBackup", "New_Selection", Expression)
If I put the county name in the expression, it works fine. The issue I'm having is with making it a parameter that can be changed.
Vince
20.5k16 gold badges49 silver badges65 bronze badges
-
Maybe this post will help: gis.stackexchange.com/questions/356650/…GBG– GBG2021年05月14日 16:15:27 +00:00Commented May 14, 2021 at 16:15
1 Answer 1
Here's the new script after figuring it out (still getting used to this website):
import arcpy
arcpy.env.workspace = r'(GDB Path)'
selectedField = 'COUNTY1'
county = arcpy.GetParameterAsText(0)
sql = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(datasource="ArmoringBackup", field='COUNTY1'), county)
arcpy.SelectLayerByAttribute_management("ArmoringBackup", "New_Selection", sql)
I must've been using the wrong delimiters and the new line does it for you.
Vince
20.5k16 gold badges49 silver badges65 bronze badges
-
1Best practice calls for only using leading uppercase for class names, not variables.Vince– Vince2021年05月14日 20:16:16 +00:00Commented May 14, 2021 at 20:16
default