Mercurial > mxd2map
annotate contrib/python/FixWorkspacePaths.py @ 214:0770d8c9999b
* website/download-de.htm4, website/index.htm4: repaired broken
links found by Hans
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Fri, 22 Jul 2011 14:11:06 +0200 |
parents | 93699e8f2d1f |
children | 4dc2b9aa3c57 |
rev | line source |
---|---|
114
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
1 import arcpy, os |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
2 |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
3 inputMXD = arcpy.GetParameterAsText(0) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
4 |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
5 newpath = r'C:\mxd-konverter\testdata-frida' |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
6 |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
7 rootdir = inputMXD |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
8 |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
9 for root, subFolders, files in os.walk(rootdir): |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
10 for file in files: |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
11 f = os.path.join(root, file) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
12 if os.path.isfile(f): |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
13 basename, extension = os.path.splitext(f) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
14 if extension.lower() == ".mxd": |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
15 print "Bearbeitet Dokument %s" % f |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
16 mxd = arcpy.mapping.MapDocument(f) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
17 #Report broken sources |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
18 if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0: |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
19 for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd): |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
20 if brkLyr.supports("dataSource"): |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
21 oldpath = brkLyr.dataSource |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
22 oldworkspace = brkLyr.workspacePath |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
23 print "Old dataSource-Path %s, old workspacePath %s " % (oldpath, oldworkspace) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
24 # Replace |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
25 brkLyr.findAndReplaceWorkspacePath(oldworkspace, newpath) |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
26 print "Corrected path: %s" % brkLyr.workspacePath |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
27 print "Corrected dataSource: %s" %brkLyr.dataSource |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
28 mxd.save() |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
29 print "Wrote file %s" % f |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
30 print arcpy.GetMessages() |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
31 else: |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
32 print "keine kaputten Layer gefunden" |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
33 |
93699e8f2d1f
contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff
changeset
|
34 del mxd |