Hi-
We are migrating from ArcMap 9.3.1 to 10.1. In the process, we have to repair some issues with broken SDE data sources for our existing map documents. We can do most of that using Python, we are able to recover/replace, the data source, simple symbology, definition query, and joins for our map documents (or layers therein).
However, we have not found a way manually or using Python (or ArcObjects) to preserve any of the more complex layer symbology, such a symbology that uses categories (e.g. draw categories using unique values of one field). Has anyone been able to do this?
We have thousands of map documents, so clearly we would prefer to be able to automate this task, as otherwise it will be thousands of hours of work.
Below is what we have working so far (except the part about suppressing the popup, but that is a minor issue for now):
Ideas? Links to the solution?
Thanks for any help you may have!
We are migrating from ArcMap 9.3.1 to 10.1. In the process, we have to repair some issues with broken SDE data sources for our existing map documents. We can do most of that using Python, we are able to recover/replace, the data source, simple symbology, definition query, and joins for our map documents (or layers therein).
However, we have not found a way manually or using Python (or ArcObjects) to preserve any of the more complex layer symbology, such a symbology that uses categories (e.g. draw categories using unique values of one field). Has anyone been able to do this?
We have thousands of map documents, so clearly we would prefer to be able to automate this task, as otherwise it will be thousands of hours of work.
Below is what we have working so far (except the part about suppressing the popup, but that is a minor issue for now):
Ideas? Links to the solution?
Code:
import arcpy as ap
import arcpy.mapping as am
import os.path
import os
wd = r"C:\WORKSPACE"
source_mxd = r"%s\%s" % (wd, "source_mxd")
target_mxd = r"%s\%s" % (wd, "target_mxd")
new_Source_connect_file = r"C:\workspace\TempConnection.sde"
# get the current location
cwd = os.getcwd()
if cwd.upper() <> wd.upper():
os.chdir(wd)
# cleanout the target directory
for fl in os.listdir(target_mxd):
if fl.endswith(".mxd"):
mxd = r"%s\%s" % (target_mxd, fl)
print mxd
if os.path.exists(mxd):
os.remove(mxd)
# just to supress the loggon popup
#-------------------------------------------------------------------------------------------------
ConxFile = 'TempConnection.sde'
Database = ''
Server = 'MYSERVERNAME'
ServiceName = 'SERVICENAME'
authType = 'DATABASE_AUTH'
UserName = 'MYUSERNAME'
Pwd = 'myPassword'
SaveUserInfo = 'SAVE_USERNAME'
versName = 'MY.VERSIONNAME'
saveVersInfo = 'SAVE_VERSION'
print 'wd: ' + wd + ' newSourceConnectFile: ' + new_Source_connect_file
sdeFile = r"%s\%s" % ( wd, r"TempConnection.sde")
if os.path.exists(sdeFile):
os.remove(sdeFile)
ap.CreateArcSDEConnectionFile_management(wd, ConxFile,\
Server, ServiceName, Database, authType,\
UserName, Pwd, SaveUserInfo, versName,\
saveVersInfo)
#-------------------------------------------------------------------------------------------------
# Process the souce map documents
mdw = None
md = None
for fl in os.listdir(source_mxd):
if fl.endswith(".mxd"):
mxd = r"%s\%s" % (source_mxd, fl)
print "Processing %s" % (mxd)
# make a working copy in the target directory
mdw = am.MapDocument(mxd)
temp_mdw = r"%s\%s" % (target_mxd, "Temp.mxd")
print "Created Temp"
mdw.saveACopy(temp_mdw)
del mdw
#working copy is now the target copy
md = am.MapDocument(temp_mdw)
LstBrokenDataSources = am.ListBrokenDataSources(md)
for lyr in LstBrokenDataSources:
print "Processing " + lyr.longName + " for " + mxd
if lyr.supports("DATASOURCE"):
layer = lyr.dataSource
if lyr.supports("WORKSPACEPATH"):
print lyr.workspacePath
if layer.upper().find(r"TRMS.SDE") >= 0:
print "repairing Data Source"
lyr.replaceDataSource(new_Source_connect_file, "SDE_WORKSPACE", "", False)
md.saveACopy(mxd.replace(source_mxd,target_mxd))
del md
if os.path.exists(temp_mdw):
os.remove(temp_mdw)