2

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.

1

I was able to execute the code successfully.However, i did not see the layer being removed from the map service.

Your Python code above correctly removes the "test" layer from the MXD, so there are no problems with the code.

But the ArcGIS Server service does not constantly "listen" to the MXD, so changes that you make to the MXD will not automatically appear in ArcGIS Server.

Is there another way to remove the layer file from mxd document by not to deleting the service and uploading the service?

Instead, you can over-write the ArcGIS Server service using the new MXD with the layer removed.

In ArcMap, choose > File > Share As > Service, then on the following panel choose Overwrite an existing service.

enter image description here

On the following panel, find the name of the existing service to over-write.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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