I have about 100 figures that have been updated countless times and a lot of the old data was left in each .mxd but was only turned off (unchecked) and not removed. I would like to remove these layers from each .mxd but keep the actual shapefile/features in an achieve folder.

I have found a similar script that removes layers by layer name here: Delete layer from ArcMap using Python

but it does not do exactly what I want it to do.

Does anyone have a script already written that does what I am trying to do?

  • If you don't wan to delete the layer from disk, just remove the "arcpy.Delete_management(lyr.dataSource)" from the script you linked to. Commented Feb 4, 2014 at 15:36
  • Sorry. What i want to do is remove layers that are unchecked in the TOC. The linked script removes layers by name.
    – Mike
    Commented Feb 4, 2014 at 15:39
  • Closely related to How to turn off layers in ArcMap via arcpy? Commented Feb 4, 2014 at 15:55

1 Answer 1


In order to remove only layers that are unchecked (not visible), you need to check the layer property "visible". In this case you would just need to sub out:

if lyr.name == "CADAnnotation": for if lyr.visible == False:

You should read more about layer properties at Layer (arcpy.mapping) in the online help.

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.