import arcpy
arcpy.env.workspace = r'c:\data'
fcs = str(raw_input('Please enter the layers you would like to buffer: '))
dist = str(raw_input('What would you like your buffer distance to be? '))
output = str(raw_input('Name your output: '))
for fc in fcs:
if arcpy.Exists(fcs):
arcpy.Buffer_analysis(inputs, output, dist)
if not arcpy.Exists(fcs):
print "Feature class does not exist"
The above script executes but does not create the feature class I want. Where am I going wrong?
1 Answer 1
As indicated in the comments, you have a few issues. The first one I see is your enumerating through fcs. What do you expect to enter at the prompt? Your code will enumerate through each letter, which I expect is not what you want. For example, if you enter "fred, bob", the list will be: [f,r,e,d, , b,o,b].
Try:
arcpy.env.workspace = r'c:\data'
string_input = raw_input('Please enter the layers you would like to buffer: ')
fcs = map(str.strip, string_input.split(','))
dist = raw_input('What would you like your buffer distance to be? ')
output = raw_input('Name your output: ')
for fc in fcs:
if arcpy.Exists(fc):
arcpy.Buffer_analysis(fc, output, dist)
if not arcpy.Exists(fc):
print "Feature class does not exist"
Where you would enter a comma-delimited list for the layers to buffer. For example, "trees, shrubs, plants".
Warning: this is untested code, so there may be other issues. I am unsure what you want youroutput
to be as all the inputs will go to the same output feature class.
fc
value is. You supply theinputs
to the Buffer however, it should befc
. Indentation is wrong,arcpy.Buffer_analysis
should be one level to the right.