Saturday 19 August 2017

arcgis 10.0 - remove layer from mxd document using arcpy


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.





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...