1

I ran a script that I got from exporting a model that I built in Model Builder in ArcCatalog 10.3.1 and made edits to it (using the generous help from people on here). I essentially put in for my buffer, feature class to feature class, and spatial join processes to print if they already exist and then the code to delete them.

After running the script, I received this text in blue (I didn't play around with the color defaults on Python IDLE):

F:\Projects\Working\ModelProject\ModelData.gdb\Hurricanes_in_Counties_Feature_Class already exists!!
F:\Projects\Working\ModelProject\ModelData.gdb\Hurricanes_Buffer already exists!!
F:\Projects\Working\ModelProject\ModelData.gdb\Hurricanes_Counties_SpaJoi already exists!!

I was told that I need to put in the output files. My question is how do I even begin with an output file?

Here is my code for the buffer process:

import arcpy 
Hurricanes_Buffer = "F:\\Projects\\Working\\ModelProject\\ModelData.gdb\\Hurricanes_Buffer"
if arcpy.Exists(Hurricanes_Buffer):
    print "{} already exists!!".format(Hurricanes_Buffer)
    arcpy.Delete_management(Hurricanes_Buffer)

arcpy.Buffer_analysis(Hurricanes_in_Counties, Hurricanes_Buffer, v15_Miles, "FULL", "ROUND", "NONE", "", "PLANAR")
  • 1
    As per the tour, please only write one question per question – Midavalo Sep 11 '16 at 19:24
  • 1
    Please edit your question to include the snippet of code you are stuck with, and format it by selecting the code and pressing the { } button – Midavalo Sep 11 '16 at 19:25
  • 1
    I'm voting to close as this doesn't have enough info and is also too broad asking multiple questions. @PolyGeo and myself (and probably others) have spent a fair bit of time over the past few days with helping you with how to write a question in order to get good answers but you don't appear to be taking much advice. See Writing code snippets to get quicker answers – Midavalo Sep 11 '16 at 19:30
  • 1
    see my comment about about selecting your code snippet and pressing the { } button to format as code (rather than using the ` to surround your snippet) – Midavalo Sep 11 '16 at 19:36
  • 1
    OK looks much better thanks. Are you wanting to run this on one specified file at a time, or loop through a list or folder of files? These two options will require different code – Midavalo Sep 11 '16 at 19:42
2

arcpy normally doesn't overwrite existing files, so if you get this message there is a problem somewhere: you tried to write a file and this file already exist. If you where in a loop, make sure that the name of the output files is modified at each iteration.

| improve this answer | |
  • 2
    Please add your code snippet (edit your question) if you need more specific help. It is not possible to guess exactly what you are doing in this case. If you tried to run it and don't have a loop, then change the names of your files in arccatalog so that new files are not conflicting – radouxju Sep 11 '16 at 19:23
  • Thanks. But I'm still confused. Do I need to create new files for those processes to put their output into? – MapsandCats Sep 11 '16 at 19:25
  • 2
    no, most tools create an output file and those file must not already exist – radouxju Sep 11 '16 at 20:17
1

I think you would be better served by:

import arcpy
arcpy.overwriteOutput = True

Than delete

http://help.arcgis.com/En/Arcgisdesktop/10.0/Help/index.html#//00210000000q000000

Overwrite tool output section explains why

| improve this answer | |
  • 2
    Just be careful when turning on Overwrite that you don't inadvertently overwrite stuff you want to keep, like the last instance of running a tool for 40 hours. – Michael Stimson Sep 11 '16 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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