I have a few basemaps published to ArcGIS Server. I have a script that I am running which removes these basemap map services. What I need to do is find the source REST endpoints of these mapservices to further narrow down my script. I have just added as per @Vince suggestion the isServiceLayer as an if statement and tried printing out the serviceProperties but the script throws an error on certain layers
sample UPDATED code...
f = path
mxd = arcpy.mapping.MapDocument(r'{}'.format(f))
for df in arcpy.mapping.ListDataFrames(mxd):
for x in arcpy.mapping.ListLayers(mxd,data_frame=df):
if x.isGroupLayer:
name = str(x)
if name.startswith("Basemaps"):
if x.isServiceLayer:
print x.serviceProperties
arcpy.mapping.RemoveLayer(df,x)
ERROR
_Basemaps_hcgis
_Basemaps_hcgis\ Region
{u'UserName': u'arcgis', u'Supportsrsa': u'-1', u'ServiceType': u'MapServer', u'Connectionfile': u'C:\\Users\\\\AppData\\Roaming\\ESRI\\Desktop10.3\\ArcCatalog\\arcgis on SERVER (admin).ags', u'Connectionmode': u'1', u'URL': u'http://SERVER', u'Servertype': u'1', u'Restversion': u'10.3', u'Rsaurl': u'http://SERVER', u'Server': u'', u'Adminurl': u'http://SERVER', u'Resturl': u'http://SERVER', u'Soapurl': u'http://SERVER', u'Handshakefinished': u'-1', u'Anonymous': u'0', u'Usedefaultstagingfolder': u'-1', u'Admintokenurl': u'http://SERVER', u'Stagingfolder': u'C:\\Users\\\\AppData\\Local\\Temp\\arc434C\\Staging'}
_Basemaps_hcgis\ Region\>570000
Traceback (most recent call last):
File "C:\Users\Desktop\blah.py", line 11, in <module>
print x.serviceProperties
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjects\_base.py", line 78, in _get
(attr_name, self.__class__.__name__))
NameError: The attribute 'serviceProperties' is not supported on this instance of Layer.
UPDATE from @Alex suggestions:
my mapserver basemaps are in a group layer named Basemaps and I only want to remove those basemaps... the problem is I am running this script through network drives so some of the old MXDS(before my time) have two group layers called Basemaps group layer, 1 from the old server and 1 from the new one. I DO NOT want to remove the new **Basemaps ** group layer and the only way to accomplish this is to open up each mapservice and check which server it is from... here is a picture of how it is set up
ListLayers
does not restrict by data frame (your code would not work with multiple data frames). The Layer documentation lists the properties, including.isServiceLayer
and.serviceProperties
– Vince Mar 16 '18 at 13:47ListLayers(...,data_frame=df)
to use your current looping structure – Vince Mar 16 '18 at 13:54