Select to view content in your preferred language

Using a list for selection

598
2
Jump to solution
04-18-2012 08:52 AM
ChadFoster
Deactivated User
I am using Arc10 SP4.

I have a script completed for Parcel Noticing, it asks the user to input one parcel number and then runs through the script.  We sometimes have to select multiple parcels for noticing.

How would I go about starting a script using an excel file or text file that contains a list of parcel numbers?  I want to create a script that allows the user the ability to select a file that contains a list of parcel numbers, have the script create a list that can be used in python to do a multiple selection.

layer = arcpy.GetParameterAsText(0) apnlist = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames (mxd, "LAYERS")[0]


What data type parameter property should i use? ie, string or file

Once this is determined, how do I go about turning that input into a list that I can use to create a selection?

I am assuming it is going to be a for loop like this:

for apn in apnlist:     selstring = """TAG = '{0}'""".format(apn)     arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", selstring)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RyanForbes1
Occasional Contributor
I am not 100% sure how to consume an excel document, but a text file or csv is very straight forward.

The input from the user you would need is a path to the text document.  I think taking the input as a file returns the path as a string.

inFile = open("C:\sample.txt", "r")  inString = inFile.read() # You change the ", " to whatever is delimiting your numbers in the text file / CSV outList = inString.split(", ")  # And then you're right, you would do a for loop on the list to isolate each indiviudal number. for number in outList:  print number

View solution in original post

0 Kudos
2 Replies
RyanForbes1
Occasional Contributor
I am not 100% sure how to consume an excel document, but a text file or csv is very straight forward.

The input from the user you would need is a path to the text document.  I think taking the input as a file returns the path as a string.

inFile = open("C:\sample.txt", "r")  inString = inFile.read() # You change the ", " to whatever is delimiting your numbers in the text file / CSV outList = inString.split(", ")  # And then you're right, you would do a for loop on the list to isolate each indiviudal number. for number in outList:  print number
0 Kudos
ChadFoster
Deactivated User
Ryan,

Thanks for the help, it worked great!

Chad
0 Kudos