HowTo:  Extract server and database properties from layers in an MXD file

相关信息
Article ID: 41112
Software:
ArcSDE 10.1
ArcGIS for Desktop Advanced 10.1
ArcGIS for Desktop Standard 10.1
ArcGIS for Desktop Basic 10.1
Platforms:
Windows Server 2003, Vista, Server 2008, Windows 7, Windows 8

问题描述
GIS administrators and managers sometimes need to ascertain the server and database properties of layers in .mxd files in an automated fashion. Instructions provided describe how to do this using a Python script.
已邀请:

EsriSupport

赞同来自:

解决方案
The below Python script demonstrates how to extract database and server properties for layers and tables in an .mxd file.
  1. Modify the below parameter to point to an .mxd file: 
    mxd_source = r"C:\DATA\test_name.mxd"

2.
import arcpy, os, string

def FindConnPropTbl(mxd_source):
mxd = arcpy.mapping.MapDocument(mxd_source)
for df in arcpy.mapping.ListDataFrames(mxd):
tableList = arcpy.mapping.ListTableViews(mxd, "", df)
for table in tableList:
dsource = str(table.dataSource)
fnd = dsource.find('.sde')
sub_str = dsource[:fnd +4]
desc = arcpy.Describe(sub_str)
cp = desc.connectionProperties
try:
print "Table:{0},Server: {1}".format(table.name,cp.server)
except:
print "No server listed for table: {0}".format(table.name)
try:
print "Table:{0},Database: {1}".format(table.name,cp.database)
except:
print "No database listed for table: {0}".format(table.name)
del table,dsource,fnd,cp,sub_str,desc
del mxd,df,tableList

def FindConnPropFc(mxd_source):
mxd = arcpy.mapping.MapDocument(mxd_source)
for df in arcpy.mapping.ListDataFrames(mxd):
layerList = arcpy.mapping.ListLayers(mxd, "", df)
for layer in layerList:
dsource = str(layer.dataSource)
fnd = dsource.find('.sde')
sub_str = dsource[:fnd +4]
desc = arcpy.Describe(sub_str)
cp = desc.connectionProperties
try:
print "Layer:{0},Server: {1}".format(layer.name,cp.server)
except:
print "No server listed for layer: {0}".format(layer.name)
try:
print "Layer:{0},Database: {1}".format(layer.name,cp.database)
except:
print "No database listed for layer {0}".format(layer.name)
del layer,dsource,fnd,cp,sub_str,desc
del mxd,df,layerList

if __name__=="__main__":
mxd_source = r"C:\DATA\test_name.mxd"
FindConnPropTbl(mxd_source)
FindConnPropFc(mxd_source)


创建及修改时间
Created: 4/16/2013

Last Modified: 8/6/2013
原文链接
http://support.esri.com/en/kno ... 41112

要回复问题请先登录注册