I am trying to remove layers from an ArcGIS Pro 1.1 project, but I receive a ValueError with the traceback of
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 1280, in removeLayer return convertArcObjectToPythonObject(self._arc_object.removeLayer(*gp_fixargs((remove_layer,), True)))
Here is code to add raster layers from a geodatabase
rasters = arcpy.ListRasters("*",None) aprx = arcpy.mp.ArcGISProject("Path/to/aprx") aprxMap = aprx.listMaps("Map") for raster in rasters: raster = env.workspace + "\\" + raster aprxMap.addDataFromPath(raster) aprx.save()
This successfully adds the raster objects as layers to the current map, but when I try to remove using the following code, I get an error.
for raster in rasters: aprxMap.removeLayer(raster) aprx.save()
Any ideas why this is happening?
Raster is a string, and when I have tried to write as an input string, I still receive the error.