Select to view content in your preferred language

Remove Shapefiles in .mxd

2582
2
08-27-2012 08:43 AM
MarkLazano
New Contributor
Can I remove shapefiles from my TOC in an mxd using python?  I'm thinking that removelayer is reserved for feature layers only.  I want to remove/turn off old shapefiles that had been used to create new ones to unclutter my map.

Thanks,

Eric
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
Code example would be useful.   Did you try it?
0 Kudos
JeffBarrette
Esri Regular Contributor
A layer in the TOC is a layer regardless of the source.  arcpy.mapping.RemoveLayer() should simply work.

mxd = arcpy.mapping.MapDocument("current")                      #or provide full path to MXD
df = arcpy.mapping.ListDataFrames(mxd, "df name")              #replace with actual df name
lyr = arcpy.mapping.ListLayers(mxd, "MyShapeFileLayer")[0]  #replace with acutal layer name in TOC
arcpy.mapping.RemoveLayer(df, lyr)
mxd.save()


Jeff
0 Kudos