I am very new to Python.
I built a model in the ModelBuilder in a toolbox in ArcCatalog 10.3.1. I keep getting the following error about my buffer not being able to be executed and that my parameters are not valid. I set a field for a distance value for my buffer, my buffer, and a spatial join output as Model Parameters in my model builder before I exported the script to Python to run in Python IDLE:
Traceback (most recent call last): File "F:\Projects\Working\HurricanesSCRIPT.py", line 49, in arcpy.Buffer_analysis(Hurricanes_in_Counties, Hurricanes_Buffer, v15_Miles, "FULL", "ROUND", "NONE", "", "PLANAR") File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 692, in Buffer raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000725: Output Feature Class: Dataset F:\Projects\Working\ModelProject\ModelData.gdb\Hurricanes_Buffer already exists. Failed to execute (Buffer).
I have already put in arcpy.env.overwriteOutput = True
just below import arcpy
.
Here is the script for my arguments:
# Script arguments
v15_Miles = arcpy.GetParameterAsText(0)
if v15_Miles == '#' or not v15_Miles:
v15_Miles = "15 Miles" #15 Miles
Hurricanes_Counties_SpaJoi = arcpy.GetParameterAsText(1)
if Hurricanes_Counties_SpaJoi == '#' or not Hurricanes_Counties_SpaJoi:
Hurricanes_Counties_SpaJoi = "F:\\Projects\\Working\\ModelProject\\ModelData.gdb\\Hurricanes_Counties_SpaJoi" # provide a default value if unspecified
Hurricanes_Buffer = arcpy.GetParameterAsText(2)
if Hurricanes_Buffer == '#' or not Hurricanes_Buffer:
Hurricanes_Buffer = "F:\\Projects\\Working\\ModelProject\\ModelData.gdb\\Hurricanes_Buffer" # provide a default value if unspecified
And here is the script for my buffer:
# Process: Buffer
arcpy.Buffer_analysis(Hurricanes_in_Counties, Hurricanes_Buffer, v15_Miles, "FULL", "ROUND", "NONE", "", "PLANAR")
1 Answer 1
Add a check for whether the buffer feature class exists before you run your buffer. You can use this check to delete the existing buffer, or just print a message.
# Script arguments
v15_Miles = "15 Miles" #15 Miles
Hurricanes_Counties_SpaJoi = "F:\\Projects\\Working\\ModelProject\\ModelData.gdb\\Hurricanes_Counties_SpaJoi" # provide a default value if unspecified
Hurricanes_Buffer = "F:\\Projects\\Working\\ModelProject\\ModelData.gdb\\Hurricanes_Buffer" # provide a default value if unspecified
if arcpy.Exists(Hurricanes_Buffer):
print "{} already exists!!".format(Hurricanes_Buffer)
arcpy.Delete_management(Hurricanes_Buffer)
arcpy.Buffer_analysis(Hurricanes_Counties_SpaJoi, Hurricanes_Buffer, v15_Miles, "FULL", "ROUND", "NONE", "", "PLANAR")
I have used Hurricanes_Counties_SpaJoi
in place of Hurricanes_in_Counties
in the Buffer as Hurricanes_in_Counties
wasn't defined in your arguments.
Additionally, check the caps are in the right place in your arcpy.env.overwriteOutput = True
. This one (copied from your question above) is correct, however if the O
from Output or the T
from True are lower-case the overwriteOutput will not be set. Double-check that this is how you've used it in your script.
-
That worked. However, I got a new error but I'm going to see what I can do.MapsandCats– MapsandCats2016年09月10日 21:12:19 +00:00Commented Sep 10, 2016 at 21:12
-
@MapsandCats take note of my comment about the variable names (right after my code sample) - this will be why you're getting a name error when you try to run it as per your other question.2016年09月11日 10:01:54 +00:00Commented Sep 11, 2016 at 10:01
Hurricanes_in_Counties
? You have used this variable in yourarcpy.Buffer_analysis()
, but it is not defined in your arguments above.