1

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
asked May 14, 2021 at 15:30
1

1 Answer 1

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
answered May 14, 2021 at 20:00
1
  • 1
    Best practice calls for only using leading uppercase for class names, not variables. Commented May 14, 2021 at 20:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.