I would like to remove some layers from the MXD document currently used by a service in the ArcGis Server. I am using arcpy to achieve this task. Here is my code for removing layers from MXD Documents:
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Empty.mxd") for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name.lower() == "test": arcpy.mapping.RemoveLayer(df, lyr) mxd.saveACopy(r"C:\Project\test2.mxd") del mxd
I was able to execute the code successfully.However, i did not see the layer being removed from the map service.
I tried to restart the service but it cannot remove the shape files after restarting the service.
The only way i managed to remove the layer is by deleting the service and uploading the service.
Is there another way to remove the layer file from mxd document by not to deleting the service and uploading the service? This is because uploading and deleting the service take quite long in the ArcGis Server.