Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  RyanDalton Feb 4 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 Feb 4 at 15:39
    
Closely related to How to turn off layers in ArcMap via arcpy? –  RyanDalton Feb 4 at 15:55
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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