Hi - I'm trying to remove WMS layers from an mxd using arcpy. I can successfully remove "MapServer" type services using the below code, but not WMS?Any ideas? Is arcpy.mapping.RemoveLayer the best approach ? I have hundreds of mxds to crawl through and want to remove WMS layers from them.Here's my mxd with two different WMS layers in for reference: here
import arcpy, os
inFName = "wms.mxd"
outFName = "wms_removed.mxd"
pth = r"c:\temp"
inFULLPTH = os.path.join(pth,inFName)
outFULLPTH = os.path.join(pth,outFName)
mxd = arcpy.mapping.MapDocument(inFULLPTH)
for df in arcpy.mapping.ListDataFrames(mxd):
LyrList = arcpy.mapping.ListLayers(mxd, "", df)
print LyrList
for lyr in LyrList:
if lyr.supports("SERVICEPROPERTIES"):
if lyr.serviceProperties["ServiceType"] == "WMS":
print "Removing: " + lyr.name + ": " + lyr.serviceProperties["ServiceType"]
arcpy.mapping.RemoveLayer(df, lyr)
mxd.saveACopy(outFULLPTH)
del mxd