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.
Solved! Go to Solution.
Can't tell what else your complete script is doing, but file GDB's do not support concurrent writing and if you have the layers loaded in the TOC, it won't overwrite and fail if ran from outside of the Pro env (python window).
It works in the Pro window because it is using the lock/ env that has the rights/lock to that fgdb.
Can't tell what else your complete script is doing, but file GDB's do not support concurrent writing and if you have the layers loaded in the TOC, it won't overwrite and fail if ran from outside of the Pro env (python window).
It works in the Pro window because it is using the lock/ env that has the rights/lock to that fgdb.
What is written is all the code does. loop over the feature class in the demo.gdb and creates a buffer for each and saves it to results.gdb.
I understand that there no solution for that problem; if the file I try to o\w from an external IDE is occupied by Pro env the code run will fail with that error.
I made a workaround that is not as neat as I wanted, by adding the current pc EPOCH time as a suffix to the created buffer file, thus it retains a unique name and works if I run it from IDLE while the project is loaded to Pro env.
Thank you for your clarification tho. Much appreciated.