AnsweredAssumed Answered

Trouble Accessing Layers with Python

Question asked by octaffle on Apr 13, 2015
Latest reply on Apr 13, 2015 by bixb0012

In case you've been following my fairly boring saga: I am making progress on my program!  I have my files going where they need to go! Yay!


I am trying to remove intermediate and unnecessary layers from the map document.  I have a raster file, "SoilUnclass", that I want to remove from my map document to de-clutter my Table of Contents. I put the following code together based on what I've seen and read. I left my variable definitions out of the code but my inputs are all initialized with the proper file paths.


SoilUnclass = arcpy.PolygonToRaster_conversion(soil, "HSG", ScratchPath + r"\SoilUnclass",
SoilClass =, "HSG",[["A", 1],
  ["B", 2],
  ["C", 3],
  ["D", 4],
  ["A/D", 14],
  ["B/D", 24],
  ["C/D", 34],
  ["---", 4]]), "NODATA") + r"\SoilClass") + r"\SoilClass")
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
arcpy.mapping.RemoveLayer(df, SoilUnclass)


When I run that code, I receive the following error:


Runtime error

Traceback (most recent call last):

  File "<string>", line 2, in <module>

  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\", line 182, in fn_

    return fn(*args, **kw)

  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\", line 1845, in RemoveLayer

    assert isinstance(remove_layer, Layer)



...?? It may be worth noting that when I do arcpy.mapping.ListLayers(mxd), "SoilUnclass" is not a layer that shows up.  Only the files that were in the map document before I ran my code are listed.  I saved my document and did ListLayers() again but nothing changed.  How can I get access to these layers to modify them?