Mercurial > mxd2map
comparison contrib/python/FixWorkspacePaths.py @ 114:93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Added some sample-scripts for working with MXD-files
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 16:13:32 +0200 |
parents | |
children | 4dc2b9aa3c57 |
comparison
equal
deleted
inserted
replaced
113:0db6eacad0e6 | 114:93699e8f2d1f |
---|---|
1 import arcpy, os | |
2 | |
3 inputMXD = arcpy.GetParameterAsText(0) | |
4 | |
5 newpath = r'C:\mxd-konverter\testdata-frida' | |
6 | |
7 rootdir = inputMXD | |
8 | |
9 for root, subFolders, files in os.walk(rootdir): | |
10 for file in files: | |
11 f = os.path.join(root, file) | |
12 if os.path.isfile(f): | |
13 basename, extension = os.path.splitext(f) | |
14 if extension.lower() == ".mxd": | |
15 print "Bearbeitet Dokument %s" % f | |
16 mxd = arcpy.mapping.MapDocument(f) | |
17 #Report broken sources | |
18 if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0: | |
19 for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd): | |
20 if brkLyr.supports("dataSource"): | |
21 oldpath = brkLyr.dataSource | |
22 oldworkspace = brkLyr.workspacePath | |
23 print "Old dataSource-Path %s, old workspacePath %s " % (oldpath, oldworkspace) | |
24 # Replace | |
25 brkLyr.findAndReplaceWorkspacePath(oldworkspace, newpath) | |
26 print "Corrected path: %s" % brkLyr.workspacePath | |
27 print "Corrected dataSource: %s" %brkLyr.dataSource | |
28 mxd.save() | |
29 print "Wrote file %s" % f | |
30 print arcpy.GetMessages() | |
31 else: | |
32 print "keine kaputten Layer gefunden" | |
33 | |
34 del mxd |