-1
taxNo = arcpy.GetParameterAsText(0)
thisMap = arcpy.mapping.MapDocument("CURRENT")
myDF = arcpy.mapping.ListDataFrames(thisMap)[0]
myLayers = arcpy.mapping.ListLayers(myDF)
for lyr in myLayers:
if lyr.name == "Address Numbers":
    arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION","EKEY = " + taxNo[0])
    for tax in taxNo:
        arcpy.SelectLayerByAttribute_management(lyr,"ADD_TO_SELECTION","EKEY = " + tax)
        arcpy.AddWarning("Additional Selection " + tax)

I'm trying to build a script in ArcGIS that will select a series of user defined values, in this case I'm trying to select 1784102 and 1784110. When I use arcpy.AddWarning(taxNo) before the loop, I get the output "1784102;1784110" but it's iterating through it one number at a time i.e.

Additional Selection 1

Additional Selection 7

Additional Selection 8

Additional Selection 4 etc.

then pops up an error when it hits the semi-colon. The parameters for taxNo are set up in ArcMap as a String, Multivalue, Valuelist.

CBode
  • 3
  • 1

1 Answers1

1

I will just assume you are calling your script like this:

python script.py 1784102;1784110

Your variable taxNo = arcpy.GetParameterAsText(0) then is a single string "1784102;1784110". If you use "array indexes" on strings (for example taxNo[0], taxNo[1] etc.) you are getting single characters out of that string, i.e. "1", "7", "8" ...

Call .split(';') to your arcpy.GetParameterAsText(0) result to split the string "1784102;1784110" into an array of two strings: ["1784102", "1784110"]. If you need a numeric item, i.e. integers, try this too.

taxNo = arcpy.GetParameterAsText(0).split(';')
Community
  • 1
  • 1
chrki
  • 6,143
  • 6
  • 35
  • 55