I'm writing an add-in for Arcmap and at the end of it I am left with multiple layers from buffers, joins, and selections. I am trying to delete these layers before the add-in finishes so to keep the number of layers in TOC to a minimum. Below is the piece of code I am using to delete the layers, and the error it raises.

f = ['Select_1', 'Join_1', 'Buff_1']
for x in f:


Runtime error Traceback (most recent call last): File "", line 2, in File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\management.py", line 4359, in Delete raise e ExecuteError: ERROR 000622: Failed to execute (Delete). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_data.


1 Answer 1


It looks like you may be interested in the RemoveLayer function in the mapping module. Or specify that intermediate layers should not be added to the TOC.

Depending upon your workflow, you may be able to use in_memory workspace to manage intermediate data. Here is a post on GIS SE that addresses managing intermediate data with in_memory workspace.

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.