1

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 rasies.

f = ['Select_1', 'Join_1', 'Buff_1']
for x in f:
    arcpy.Delete_management(x)

Error:

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.

  • 4
    It looks like you may be interested in the RemoveLayer function: desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/… 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. – Aaron Feb 13 '20 at 16:18
  • 2
    Please Edit the question so that the error message is in text. An image is not legible on all devices and can't be searched by others looking for a similar error. – Vince Feb 13 '20 at 16:19
  • 2
    Agreed - you're wanting to Remove layers, not Delete them. Delete_management() is for deleting data (permanently), not remove a layer from your map – Midavalo Feb 13 '20 at 16:20
  • Have you tried setting the workspace (ex/ arcpy.env.workspace = "C:/path_to_data") at the top of your Python. Also, consider adding "if arcpy.Exists(x):" above the Delete to check if the file exists before deleting. – jdavid05 Feb 13 '20 at 16:21
  • 2
    Yes. Here is a related post and answer on using in_memory workspace: gis.stackexchange.com/a/88534/8104 – Aaron Feb 13 '20 at 16:31
3

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, privacy policy and cookie policy

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