I wrote the following piece of code that loops over a map features and buffer them. new buffer layers are saved to a different gdp with in this project.
If I run the code from IDLE while that project is not open in ArcGIS than I can run it many times and the files in the results.gdb gets overwrite with no issues. However, if I try to run the code from IDLE while that same project is open in ArcGIS and if the buffer files to be created by that code already exists (same file name) in the results.gdb (output path; destination) them I get and error that the buffer method failed:
ERROR 000258: Output C:\\Users\\User\\Desktop\\PythonClassHWEx\\L8_HomeWore\\Ex8\\results.gdb\routes1_buffer already exists
Failed to execute (Buffer).
If I try to add an IF-BLOCK to check if the file by that name already exists and then delete it before saving new buffer layer with the same name, I get an error that the schema is locked:
Error ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application or service.
Failed to execute (Delete).
The code I'm trying to execute:
import arcpy.md
#function to captue ArcPro project file elements
#and create a pre-defined buffer area around them
#init variables
arcpy.env.workspace = r"C:\\Users\\User\\Desktop\\PythonClassHWEx\\L8_HomeWore\\Ex8\\demo.gdb"
arcpy.env.overwriteOutput = True
featureclasses = arcpy.ListFeatureClasses()
bufferDistance = '850'
try:
for fc in featureclasses:
output = r"C:\\Users\\User\\Desktop\\PythonClassHWEx\\L8_HomeWore\\Ex8\\results.gdb\\"+fc+'_buffer'
arcpy.Buffer_analysis(in_features=fc, out_feature_class=output, buffer_distance_or_field=bufferDistance+" Meters", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field=[], method="PLANAR")
except Exception as e:
print("Error " + e.args[0])
print('Done!')
This code run just fine if using the build-in ArcGIS Pro python window and it overwrites whatever file with same name(s) are in the output path gdb. As many time as I execute it. No errors.
Any direction or help is highly appreciated.