0
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?

3
  • 1
    Debug your code to see what is the fc value is. You supply the inputs to the Buffer however, it should be fc. Indentation is wrong, arcpy.Buffer_analysis should be one level to the right. Mar 24, 2015 at 10:19
  • Print the contents of each variable before you use them - I think you are assuming that they have a value different to what is actually being stored.
    – PolyGeo
    Mar 24, 2015 at 10:39
  • Any time you take a user entered string you should check the entry to make sure it's valid. For example, someone could enter 'abc' for dist. This would, obviously, be incorrect.
    – recurvata
    Mar 24, 2015 at 12:07

1 Answer 1

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.