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"
Document versioning needs to be added. Please add this to the ideas site.
>>> if mapServiceGrp0.supports("SERVICEPROPERTIES"): ... for i, j in mapServiceGrp0.serviceProperties.iteritems(): ... print "{0}: {1}".format(i, j) ... UserName: ServiceType: MapServer Connectionfile: C:\Documents and Settings\whitley-wayne\Application Data\ESRI\Desktop10.0\ArcCatalog\mc-gisappserver (admin).ags URL: Managerurl: http://mc-gisapperver/arcgis/services Server: mc-gisappserver Allowinsecuretokenurl: 0
>>> # This 1st one is an SDE 'service' - have to distinguish between SDE and other supporting service layer... >>> mm = mapLyrs[0] >>> mm.name u'MonroeGISData.DBO.BM_MileMarkers' >>> # so I could have queried a bit further to get type 'SDE' above...but with DBO in the name I already know. >>> # This 2nd layer is the map service from 1st code section above - I need the name. >>> mapServiceGrp0 = mapLyrs[1] >>> mapServiceGrp0.name u'MonroeCountySDE_Environmental_Layout'
This is a little testing on one of my 10.0 map services, and I think you'll get the picture: >>> if mapServiceGrp0.supports("SERVICEPROPERTIES"): ... for i, j in mapServiceGrp0.serviceProperties.iteritems(): ... print "{0}: {1}".format(i, j) ... UserName: ServiceType: MapServer Connectionfile: C:\Documents and Settings\whitley-wayne\Application Data\ESRI\Desktop10.0\ArcCatalog\mc-gisappserver (admin).ags URL: Managerurl: http://mc-gisapperver/arcgis/services Server: mc-gisappserver Allowinsecuretokenurl: 0
UserName: ServiceType: MapServer Connectionfile: C:\Users\kreuzrsk\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\arcgis on aimsw.xyz.wa.ags URL: http://aimsw.xyz.wa.lcl/arcgis/services Server: Allowinsecuretokenurl: 0 Anonymous: -1
>>> mapLyrs = arcpy.mapping.ListLayers(mxd) >>> mapLyrs [<map layer u'MonroeGISData.DBO.BM_MileMarkers'>, <map group layer u'test'>, <map group layer u'Overview'>, <map layer u'MileMarker'>, <map layer u'Overseas Hwy - US 1'>, <map layer u'Base Map Annotation Water'>, <map group layer u'Base Map Annotation'>, <map layer u'Overview'>, <map layer u'Overview Island Level'>, <map layer u'Monroe County Boundary'>, <map layer u'Miami-Dade County Boundary'>, <map group layer u'MCPA'>, <map layer u'Roads'>, <map group layer u'Parcel ID Text'>, <map layer u'Default'>, <map layer u'Parcels'>, <map group layer u'Historic Areas'>, <map layer u'Historical Structures'>, <map layer u'Tavernier Historic District'>, <map layer u'Marsh Rabbit Buffer'>, <map layer u'Marsh Rabbit Habitat'>, <map layer u'Endangered Species'>, <map layer u'Habitat 2009'>, <map group layer u'Tier Overlay District'>, <map layer u'Tier Overlay District'>, <map layer u'Tier Labels'>, <map group layer u'FEMA'>, <map layer u'Flood hazard zone lines'>, <map layer u'DFIRM panel labels'>, <map layer u'Flood hazard zone text'>, <map layer u'CBRS'>, <map layer u'Zoning'>, <map layer u'FLUM (Draft)'>, <map layer u'2006 Orthophotography'>, <map layer u'2009 Orthophotography'>, <map layer u'2012 image catalog'>]
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.