importarcpy, os
#
该文件夹下的
mxd
将批量执行
mxdFolderPath = r"C:\temp\GJHY-16"
#
加
'r'
避免被转义
,
如
\t
#
旧的数据源
#
数据库连接
\orcl.sde
oldDataSources
=
r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\GJHY2.sde"
#
oldDataSources
=
r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connection
to
127.0.0.1.sde"
#
oldDataSources
=
r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connection
to
10.1.4.22.sde"
#
新的数据源
newDataSources
=
r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\GJHY.sde"
#
是否要求新数据源有效
validateNewDataSources = False
saveFolderPath = os.path.join(mxdFolderPath,"save")
if not os.path.exists(saveFolderPath):
os.mkdir(saveFolderPath)
for filename in os.listdir(mxdFolderPath):
fullpath = os.path.join(mxdFolderPath, filename)
ifos.path.isfile(fullpath):
basename, extension = os.path.splitext(filename)
ifextension.lower() == ".mxd":
mxd = arcpy.mapping.MapDocument(fullpath)
printfullpath
#debug
print "====================
更改前:
====================="
brknList = arcpy.mapping.ListBrokenDataSources(mxd)
print "BrokenDataSources
个数
:%d" % len(brknList)
print "
【数据源损坏的图层】
:
"
iflen(brknList)>0:
forlyr in brknList:
print "- " + lyr.name
print "\t" + lyr.dataSource
# print "
【所有图层】
:
"
# forlyr in arcpy.mapping.ListLayers(mxd):
#
print "- " + lyr.name
#
iflyr.supports("DATASOURCE"):