import os, arcpy
start = r"G:\DEPARTMENTS\GIS\Chris_Graff\temp\scketchup"
sdeFile = r"G:\DEPARTMENTS\GIS\Chris_Graff\temp\Aerial.sde"
for root, dirs, files in os.walk(start):
for file in files:
if file.endswith(".mxd"):
path = os.path.abspath(os.path.join(root,file))
mxd = arcpy.mapping.MapDocument(path)
print path
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES") and lyr.serviceProperties["ServiceType"] == "SDE":
if lyr.datasetName.upper() == "STATIC.DATALOADER.AP2008":
print "! " + lyr.datasetName
lyr.replaceDataSource(sdeFile, "SDE_WORKSPACE", r"AERIAL.DATALOADER.AP2008", True)
print "NEW " + lyr.datasetName
else:
if lyr.isRasterLayer:
print "!!!!" + lyr.datasetName
else:
print " " + lyr.datasetName
else:
print " " + lyr.name
try:
mxd.save()
except IOError as e:
print "Save failed!"
del mxd, lyr, file, path
import arcpy, os
from arcpy import env
from arcpy import mapping
env.workspace = workspace = arcpy.GetParameterAsText(0)
env.overwriteOutput = True
for (path, dirs, files) in os.walk(workspace):
for file in files:
if ".mxd" in file.lower():
mxd = os.path.join(path, file)
print mxd + " is being processed"
mxd = mapping.MapDocument(mxd)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
lyr.replaceDataSource(arcpy.GetParameterAsText(1), "SDE_WORKSPACE", "")
print "Successfully updated data sources"
if "vector" in lyr.name:
lyr.name = "RASTER.DATALOADER." + lyr.name.split(".")[2]
print "Succesfully changed layer name"
mxd.save()
del mxd if "vector" in lyr.name:
lyr.name = "raster.dataloader." + lyr.name.split(".")[2]
lyr.replaceDataSource(sdeFile, "SDE_WORKSPACE", "AERIAL.DATALOADER.AP2008", True)
lyr.replaceDataSource(sdeFile, "SDE_WORKSPACE", "AP2008", True)
lyr.replaceDataSource(sdeFile, "SDE_WORKSPACE", "", True)
lyr.replaceDataSource(sdeFile, "SDE_WORKSPACE", "newName", True)
elif layr.datasetName == "ORTHO2005.ORTHOS2005":
print("The dataset name in Resource_mxd is " + layr.datasetName)
layr.replaceDataSource(r"\\gis\GIS\Work\arcmap\mosaic_2010.gdb", "FILEGDB_WORKSPACE", "orthos_2010")