I am trying to make a quick script to report dead layers within an mxd, e.g. layers who point to a bad location in a database or to a web service that is no longer active.
I am having a hard time finding a way to get the name of the service. I would like to get the layer name from the TOC, the url of the server, and the name of the service.
Looking at the layer properties I don't see a way to get the name of the service for Map Service type.
import arcpy
mxd_path = r"xxxx"
#mxd = arcpy.mapping.MapDocument("CURRENT")
mxd = arcpy.mapping.MapDocument(mxd_path)
brknList = arcpy.mapping.ListBrokenDataSources(mxd)
dead_layer_info = []
for brknItem in brknList:
if brknItem.supports("DATASOURCE"):
dead_layer_info.append((brknItem.name, brknItem.datasetName, brknItem.dataSource))
elif brknItem.supports("SERVICEPROPERTIES") and not brknItem.supports("DATASOURCE"):
service_prop = brknItem.serviceProperties
url = service_prop.get("URL", "N/A")
# name = service_prop.get("Name???", "N/A")
dead_layer_info.append((brknItem.name, " ", url))
else:
dead_layer_info(brknItem.name, " ", " ")
dead_layer_info = list(set(dead_layer_info))
for row in dead_layer_info:
print ", ".join(row)
Current output...
You may want to give my addin a try Python addin for data inventory and “broken-link” repair. I believe I will show broken services besides other datatypes. If it doesn't do everything you are looking for, you can look at the code and see if it will help with your situation.