mport arcpy fileName = "DBS100" myMXD = "H:/_maps/" + fileName + ".mxd" print myMXD mxd = arcpy.mapping.MapDocument(myMXD) for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListBrokenDataSources(mxd): print " Broken DataSource: " + lyr.name # TableViews are erroring off because that object has no supports attribute . if lyr.supports("SERVICEPROPERTIES"): if lyr.serviceProperties['ServiceType'] == "MapServer": print lyr.serviceProperties del mxd
Thanks Matt, RemoveLayer will work. I've just got one last problem. Since I'm running this script for other users I don't want to remove all layers with broken datasources. A user may have data on their C: drive or a protected network folder, but since I'm running the script those layers show up as broken.
.The only thing I want to remove are broken map services. Unfortunately, I haven't been able to find just map services.
The line with lyr.supports("SERVICEPROPERTIES") errors off if the broken layer is a table view since TableViews don't have the SUPPORTS attribute. Any ideas.
import arcpy fileName = "DBS100" myMXD = "H:/_maps/" + fileName + ".mxd" print myMXD mxd = arcpy.mapping.MapDocument(myMXD) for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListBrokenDataSources(mxd): print " Broken DataSource: " + lyr.name # TableViews are erroring off because that object has no supports attribute . if lyr.supports("SERVICEPROPERTIES"): if lyr.serviceProperties['ServiceType'] == "MapServer": print lyr.serviceProperties del mxd
This is definitely going to be a problem. Is there anyway you can restore the old mapservices again, so you can run a python script to remove and/or replace these mapservices? Can you have both versions of ArcGIS Server running at the same time or did you upgrade in place? This would be a reason why you would want to build new servers when you upgrade your ArcGIS Server environment.
mxd = arcpy.mapping.MapDocument(myMXD) for df in arcpy.mapping.ListDataFrames(mxd): print "*** New Data Frame" print " Listing Data Frame Layers" for lyr in arcpy.mapping.ListBrokenDataSources(mxd): print " Broken DataSource: " + lyr.name # TableViews are erroring off because that object has no attribute supports. try: if lyr.supports("SERVICEPROPERTIES"): if lyr.serviceProperties['ServiceType'] == "MapServer": print "MapServer" print lyr.serviceProperties except: print "Layer has no SUPPORTS attribute: " + lyr.name
if mxd.activeDataFrame: print "Version 10.1"