<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I remove WMS layers from mxds using arcpy ? in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553998#M5997</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff - many thanks for your time. Yep - I think I can work round the remove WMS bug using the top group layer that you suggested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, a can of worms has now opened!&amp;nbsp; I've written a script to test for different types of layers in a given mxd to assist with general data management.&amp;nbsp; However, I have two further queries that have come out of this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#1 (the main problem):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to identify different layers that support services, using the: lyr.supports("SERVICEPROPERTIES") property of the Layer class in the mapping module. It seems that I can identify WMS successfully, but I'm NOT able to test ArcGIS Server map services hosted on the arcgisonline servers. For example the World Imagery layer set fails the&amp;nbsp; lyr.supports("SERVICEPROPERTIES") test. Please see below code.&amp;nbsp; Also, as requested, please find the map package to mxd/data that I've been using: &lt;/SPAN&gt;&lt;A href="http://dl.dropbox.com/u/4086367/20111025_example05_services.mpk" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding layers that are NOT Feature, Raster or Group Layers, such as CAD annotations, I've been trying to find a way to test what type of layers these are.&amp;nbsp; I've resorted to the Describe class to test that the lyr.source is a 'FeatureClass' dataType. Then hook on to the featureType to expose what type of feature it is. In this case CAD annotations = "CoverageAnnotation".&amp;nbsp; Basically, is this the best way to test Layers in mxd that support DATASOURCE, but are that are not Feature Layers ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this is all clear from the code and the map package...many thanks for your help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, string

mxdPTH = "c:\temp\example05_services.mxd"
mxd = arcpy.mapping.MapDocument(mxdPTH)

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; #loop through data frames
&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get layers list &amp;amp; loop through
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LyrList = arcpy.mapping.ListLayers(mxd, "", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in LyrList:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for group layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Group Layer Type:&amp;nbsp; " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for raster layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.isRasterLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Raster Layer Type:&amp;nbsp; " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for feature layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.isFeatureLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Feature Layer Type:&amp;nbsp; Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for service layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.supports("SERVICEPROPERTIES"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Layer Supports 'SERVICEPROPERTIES':&amp;nbsp; Service Type:&amp;nbsp; " + lyr.serviceProperties["ServiceType"] + ":&amp;nbsp; Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for non-Feature Layers that DO support DATASOURCE
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #invoke describe class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(lyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for FeatureClass Type
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.datasetType == "FeatureClass":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Non Feature-Layer Type:&amp;nbsp; Using Describe Class: FeatureClass Type:&amp;nbsp; " + str(desc.featureType) + ":&amp;nbsp; Layer Name: " + lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Non Feature-Layer Type:&amp;nbsp; Using Describe Class: Non-FeatureClass Type:&amp;nbsp; " + str(desc.datasetType) + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #catch other layer types
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Other Layer Type: Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get table list &amp;amp; loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TabList = arcpy.mapping.ListTableViews(mxd, "", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for tab in TabList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Table:&amp;nbsp; " + tab.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; del TabList
&amp;nbsp;&amp;nbsp;&amp;nbsp; del LyrList

except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback
&amp;nbsp;&amp;nbsp;&amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(str(e))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exception: " + str(e)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 23:56:45 GMT</pubDate>
    <dc:creator>RachaelYule</dc:creator>
    <dc:date>2021-12-11T23:56:45Z</dc:date>
    <item>
      <title>How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553996#M5995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my mxd with two different WMS layers in for reference: &lt;/SPAN&gt;&lt;A href="http://dl.dropbox.com/u/4086367/20111021_wms_mxd_for_esri_forum.zip" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
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):
&amp;nbsp;&amp;nbsp;&amp;nbsp; LyrList = arcpy.mapping.ListLayers(mxd, "", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print LyrList

&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in LyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("SERVICEPROPERTIES"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.serviceProperties["ServiceType"] == "WMS":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Removing: " + lyr.name + ": " + lyr.serviceProperties["ServiceType"]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)

mxd.saveACopy(outFULLPTH)
del mxd
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:56:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553996#M5995</guid>
      <dc:creator>RachaelYule</dc:creator>
      <dc:date>2021-12-11T23:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553997#M5996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I found the issue.&amp;nbsp; The root WMS service layer does not support "ServiceProperties", it is only the sub layers.&amp;nbsp; Individual sub layers can't be removed - that is also the case in the UI.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Europe BGR Geology by Age (Geochronologic)&amp;nbsp; - as the root layer - this does not support ServiceProperties but it CAN be removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Europe BGR 5M Geological Units - Offshore - this is a sub layer under the layer above.&amp;nbsp; This does support ServiceProperties but CAN NOT be removed (just like in the UI).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One possible workaround is that you identify the sub-layers but remove the parent.&amp;nbsp; This can be done by using the LYR.longName property which would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Europe BGR Geology by Age (Geochronologic)\Europe BGR 5M Geological Units - Offshore&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Find the layer with the root name("Europe BGR Geology by Age (Geochronologic)") and remove that layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps.&amp;nbsp; In the meantime, I'll mark this as a bug and hopefully get it fixed in the next service pack.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 16:32:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553997#M5996</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2011-10-24T16:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553998#M5997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff - many thanks for your time. Yep - I think I can work round the remove WMS bug using the top group layer that you suggested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, a can of worms has now opened!&amp;nbsp; I've written a script to test for different types of layers in a given mxd to assist with general data management.&amp;nbsp; However, I have two further queries that have come out of this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#1 (the main problem):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to identify different layers that support services, using the: lyr.supports("SERVICEPROPERTIES") property of the Layer class in the mapping module. It seems that I can identify WMS successfully, but I'm NOT able to test ArcGIS Server map services hosted on the arcgisonline servers. For example the World Imagery layer set fails the&amp;nbsp; lyr.supports("SERVICEPROPERTIES") test. Please see below code.&amp;nbsp; Also, as requested, please find the map package to mxd/data that I've been using: &lt;/SPAN&gt;&lt;A href="http://dl.dropbox.com/u/4086367/20111025_example05_services.mpk" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding layers that are NOT Feature, Raster or Group Layers, such as CAD annotations, I've been trying to find a way to test what type of layers these are.&amp;nbsp; I've resorted to the Describe class to test that the lyr.source is a 'FeatureClass' dataType. Then hook on to the featureType to expose what type of feature it is. In this case CAD annotations = "CoverageAnnotation".&amp;nbsp; Basically, is this the best way to test Layers in mxd that support DATASOURCE, but are that are not Feature Layers ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this is all clear from the code and the map package...many thanks for your help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, string

mxdPTH = "c:\temp\example05_services.mxd"
mxd = arcpy.mapping.MapDocument(mxdPTH)

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; #loop through data frames
&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get layers list &amp;amp; loop through
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LyrList = arcpy.mapping.ListLayers(mxd, "", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in LyrList:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for group layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Group Layer Type:&amp;nbsp; " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for raster layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.isRasterLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Raster Layer Type:&amp;nbsp; " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for feature layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.isFeatureLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Feature Layer Type:&amp;nbsp; Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for service layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.supports("SERVICEPROPERTIES"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Layer Supports 'SERVICEPROPERTIES':&amp;nbsp; Service Type:&amp;nbsp; " + lyr.serviceProperties["ServiceType"] + ":&amp;nbsp; Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for non-Feature Layers that DO support DATASOURCE
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #invoke describe class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(lyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #test for FeatureClass Type
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.datasetType == "FeatureClass":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Non Feature-Layer Type:&amp;nbsp; Using Describe Class: FeatureClass Type:&amp;nbsp; " + str(desc.featureType) + ":&amp;nbsp; Layer Name: " + lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Non Feature-Layer Type:&amp;nbsp; Using Describe Class: Non-FeatureClass Type:&amp;nbsp; " + str(desc.datasetType) + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #catch other layer types
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Other Layer Type: Layer Name: " + lyr.name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get table list &amp;amp; loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TabList = arcpy.mapping.ListTableViews(mxd, "", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for tab in TabList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Table:&amp;nbsp; " + tab.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; del TabList
&amp;nbsp;&amp;nbsp;&amp;nbsp; del LyrList

except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback
&amp;nbsp;&amp;nbsp;&amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(str(e))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exception: " + str(e)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:56:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553998#M5997</guid>
      <dc:creator>RachaelYule</dc:creator>
      <dc:date>2021-12-11T23:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553999#M5998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your first issue is very similar to the WMS layer and its sub layers.&amp;nbsp; For example, your TOC has the following layers:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
World_Imagery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; World Imagery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Low-Resolution (15m) Imagery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High-Resolution (60cm) Imagery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High-Resolution (30cm) Imagery
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The root layer "World_Imagery" is an AGS Map service and it does support "SERVICEPROPERTIES".&amp;nbsp; The problem is that you are bypassing it with the "if" lyr.isGroupLayer statement.&amp;nbsp; After that you are using "elif" statements so you never test to see if it ALSO supports service properties, you only test the sub layers which do not.&amp;nbsp; I know this is tricky.&amp;nbsp; The service layer is a group layer AND a a service layer type= MapServer.&amp;nbsp; Again this can be done with the lyr.longName property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Concerning your second issue and determining specific data types.&amp;nbsp; What gets reported from the describe statement does NOT match what you see in the UI when you go into the layers data source properties.&amp;nbsp; The UI lists one value but the arcpy.describe lists a different value.&amp;nbsp; I think the two should be the same and it should match the UI.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;UI, Data Type = CAD Annotation Feature Class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Describe.dataType = FeatureLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;UI, Feature Type = Simple&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Describe.featureType = CoverageAnnotation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This needs to be looked at.&amp;nbsp; I currently don't have a way to CAD data unless the "CAD" is in the layer name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:56:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/553999#M5998</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T23:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/554000#M5999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff - many thanks. Apologies for the delayed response. Thanks for the tip on layers being both group AND service layers, didn't think to check that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One final question that is puzzling.&amp;nbsp; In my example mxd. The first set of "World_Imagery" layers is not recognised as a Service Layer. The other two World_Imagery groups can now be identified as supporting service layers after editing my code based on your suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas why the first set of service layers fails the &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;if lyr.supports("SERVICEPROPERTIES"):&lt;/STRONG&gt;&lt;SPAN&gt; test. I guess I could identify the world imagery layer by name, but I'd have to identify all 'older' Esri service layers by name, which is not ideal.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sam&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 07:50:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/554000#M5999</guid>
      <dc:creator>RachaelYule</dc:creator>
      <dc:date>2011-10-31T07:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I remove WMS layers from mxds using arcpy ?</title>
      <link>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/554001#M6000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In my first response to this thread, I said I marked this as a bug and submitted it to our developer and it is hopefully something we can address in time for SP4.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can track it with NIM074823.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Nov 2011 14:24:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/how-can-i-remove-wms-layers-from-mxds-using-arcpy/m-p/554001#M6000</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2011-11-01T14:24:08Z</dc:date>
    </item>
  </channel>
</rss>

