raimund@256: # raimund@256: # Copyright (c) 2011 by Intevation GmbH, Germany raimund@256: # raimund@256: # This file is part of MXD2map. raimund@256: # raimund@256: # This program is free software under the LGPL (>=v2.1) raimund@256: # Read the file LICENCE.txt coming with the software for details raimund@256: # or visit http://www.gnu.org/licenses/ if it does not exist. raimund@256: # raimund@256: # MXD2map has been developed on behalf of the raimund@256: # Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg raimund@256: # by Intevation GmbH. raimund@256: # raimund@256: # Authors: raimund@256: # Raimund Renkert raimund@256: # Bjoern Schilberg raimund@256: # Stephan Holl raimund@256: stephan@114: import arcpy, os stephan@114: stephan@114: inputMXD = arcpy.GetParameterAsText(0) stephan@114: stephan@114: newpath = r'C:\mxd-konverter\testdata-frida' stephan@114: stephan@114: rootdir = inputMXD stephan@114: stephan@114: for root, subFolders, files in os.walk(rootdir): stephan@114: for file in files: stephan@114: f = os.path.join(root, file) stephan@114: if os.path.isfile(f): stephan@114: basename, extension = os.path.splitext(f) stephan@114: if extension.lower() == ".mxd": stephan@114: print "Bearbeitet Dokument %s" % f stephan@114: mxd = arcpy.mapping.MapDocument(f) stephan@114: #Report broken sources stephan@114: if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0: stephan@114: for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd): stephan@114: if brkLyr.supports("dataSource"): stephan@114: oldpath = brkLyr.dataSource stephan@114: oldworkspace = brkLyr.workspacePath stephan@114: print "Old dataSource-Path %s, old workspacePath %s " % (oldpath, oldworkspace) stephan@114: # Replace stephan@114: brkLyr.findAndReplaceWorkspacePath(oldworkspace, newpath) stephan@114: print "Corrected path: %s" % brkLyr.workspacePath stephan@114: print "Corrected dataSource: %s" %brkLyr.dataSource stephan@114: mxd.save() stephan@114: print "Wrote file %s" % f stephan@114: print arcpy.GetMessages() stephan@114: else: stephan@114: print "keine kaputten Layer gefunden" stephan@114: stephan@114: del mxd