def findAndReplaceOldPaths(mxdList, sdeList, featureDict): for mxdItem in mxdList: mxd = MapDocument(mxdItem) print "\nFor the mxd at " + str(mxdItem) print "the layers were:\n" # featureDict changes: mxdLayers = ListLayers(mxd) for mxdLayer in mxdLayers: # Might be causing locked data sources to not get changed. # If you can't access the mxdLayer source, it might not # use the supports method correctly. if mxdLayer.supports('dataSource'): layerSource = mxdLayer.dataSource print str(layerSource) if layerSource in featureDict.keys(): mxdLayer.replaceDataSource(featureDict[layerSource][0], featureDict[layerSource][1], featureDict[layerSource][2]) else: pass else: pass # sdeList changes: for sdeItem in sdeList: mxd.findAndReplaceWorkspacePaths(sdeItem[0], sdeItem[1]) print "\nThe new layers are:\n" mxdLayers = ListLayers(mxd) for mxdLayer in mxdLayers: if mxdLayer.supports('dataSource'): layerSource = mxdLayer.dataSource print str(layerSource) else: pass # Make the changes permanent. print "\nSaving mxd...\n" mxd.save() del mxd
def findAndReplaceOldPaths(mxdList, sdeList, featureDict): for mxdItem in mxdList: mxd = MapDocument(mxdItem) print "\nFor the mxd at " + str(mxdItem) print "the layers were:\n" # featureDict changes: mxdLayers = ListLayers(mxd) for mxdLayer in mxdLayers: # Might be causing locked data sources to not get changed. # If you can't access the mxdLayer source, it might not # use the supports method correctly. if mxdLayer.supports("dataSource"): layerSource = mxdLayer.dataSource print str(layerSource) if layerSource in featureDict.keys(): mxdLayer.replaceDataSource( featureDict[layerSource][0], featureDict[layerSource][1], featureDict[layerSource][2] ) else: pass else: pass # sdeList changes: for sdeItem in sdeList: mxd.findAndReplaceWorkspacePaths(sdeItem[0], sdeItem[1]) print "\nThe new layers are:\n" mxdLayers = ListLayers(mxd) for mxdLayer in mxdLayers: if mxdLayer.supports("dataSource"): layerSource = mxdLayer.dataSource print str(layerSource) else: pass # Make the changes permanent. print "\nSaving mxd...\n" mxd.save() del mxd
layers = ListLayers(mxd, "World*", df) # Use World* to include the World_Imagery layer. print layers for layer in layers: if hasattr(layer, 'visible'): layer.visible = False else: pass del layers layers = ListLayers(mxd, "CCL_REPORT*", df) # Try to remove the CCL_REPORT table. for layer in layers: try: RemoveLayer(df, layer) except: pass RefreshTOC() RefreshActiveView() mxd.save() del mxd exit()
del layers layers = ListLayers(mxd, "World*", df) # Use World* to include the World_Imagery layer. print layers for layer in layers: if hasattr(layer, 'visible'): layer.visible = False else: pass del layers layers = ListLayers(mxd, "CCL_REPORT*", df) # Try to remove the CCL_REPORT table. for layer in layers: try: RemoveLayer(df, layer) except: pass RefreshTOC() RefreshActiveView() mxd.save() del mxd exit()