Hi!
Sometime, my project .mxd crash because a layer is not well supported. So I am wondering if it is possible to remove a layer from a project without opening it (ArcGIS Desktop).
Thanks for your answer.
You could use ArcPy to do that, and run the script in ArcCatalog, ArcMap, or in an IDE like IDLE (which comes installed with ArcGIS).
Some of the classes and functions you'd probably want to use :
MapDocument—Help | ArcGIS Desktop
ListDataFrames—Help | ArcGIS Desktop
ListLayers—Help | ArcGIS Desktop
RemoveLayer—Help | ArcGIS Desktop
Here's an example:
import arcpy
arcpy.env.workspace=r"C:\DirectoryWhere\MapDocument\IsLocated"
mxd = arcpy.mapping.MapDocument("This_MXD.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layers = arcpy.mapping.ListLayers(mxd,data_frame=df)
for lyr in layers:
if(lyr.name == "remove_this_layer"):
arcpy.mapping.RemoveLayer(df,lyr)
mxd.save()
del mxd
print "Done..."
Basically what the script does is reference the MXD, point to the desired data frame, remove the desired layer based on its name, save the MXD, then delete the reference to the MXD to clear the lock on the file.