changeset 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 0db6eacad0e6
children fb93f20478cc
files ChangeLog contrib/python/FixWorkspacePaths.py contrib/python/foobar.py
diffstat 3 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jun 14 17:19:49 2011 +0200
+++ b/ChangeLog	Wed Jun 15 16:13:32 2011 +0200
@@ -1,3 +1,8 @@
+2011-06-15  Stephan Holl  <stephan.holl@intevation.de>
+
+	* contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
+	Added some sample-scripts for working with MXD-files
+
 2011-06-14  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/FeatureLayerReader.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/python/FixWorkspacePaths.py	Wed Jun 15 16:13:32 2011 +0200
@@ -0,0 +1,34 @@
+import arcpy, os
+
+inputMXD = arcpy.GetParameterAsText(0)
+
+newpath = r'C:\mxd-konverter\testdata-frida'
+
+rootdir = inputMXD
+
+for root, subFolders, files in os.walk(rootdir):
+    for file in files:
+        f = os.path.join(root, file)
+        if os.path.isfile(f):
+            basename, extension = os.path.splitext(f)
+            if extension.lower() == ".mxd":
+                print "Bearbeitet Dokument %s" % f
+                mxd = arcpy.mapping.MapDocument(f)
+                #Report broken sources
+                if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0:
+                    for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd):
+                        if brkLyr.supports("dataSource"):
+                            oldpath =  brkLyr.dataSource
+                            oldworkspace =  brkLyr.workspacePath
+                            print "Old dataSource-Path %s, old workspacePath %s " % (oldpath, oldworkspace)
+                            # Replace
+                            brkLyr.findAndReplaceWorkspacePath(oldworkspace, newpath)
+                            print "Corrected path: %s" % brkLyr.workspacePath
+                            print "Corrected dataSource: %s" %brkLyr.dataSource
+                            mxd.save()
+                            print "Wrote file %s" % f
+                            print arcpy.GetMessages()
+                else:
+                    print "keine kaputten Layer gefunden"
+            
+del mxd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/python/foobar.py	Wed Jun 15 16:13:32 2011 +0200
@@ -0,0 +1,68 @@
+# Author:  ESRI
+# Date:    July 5, 2010
+# Version: ArcGIS 10.0
+# Summary: This script will add a layer file into a map document. The script
+#          must be run from within ArcMap because it references the CURRENT
+#          map document.  The purpose of the script is to create a user
+#          friendly tool that allows users to simply add a layer from a list
+#          of existing layer files all stored in a common location. A validation
+#          script is used to automatically populate two of the parameters.
+#          The parameters are:
+#               1) Browse to a folder that contains layer files. This could be
+#                  hard coded within the validation script eliminating the need
+#                  for entering this parameter.
+#               2) Select a layer file from the list.  This is auto populated
+#                  using a validation script.
+#               3) Select a data frame.  This is also auto populated using a 
+#                  validation script.
+#               4) Select one of 3 placement positions.
+#
+# Note: This script tool will only work if background processing is disabled.
+#       because CURRENT is being used.
+# Note: To run the script from ArcMap either run the script tool from the
+#       Catalog window from within ArcMap or add the script tool into the UI
+#       via the customize dialog box [Geoprocessing Tools].
+
+import arcpy
+import shlex, subprocess
+
+#Helper for executing an external shell-scrip or programm
+def executeCommand(command):
+    success = False
+    try:
+        args = shlex.split(command)
+        p = subprocess.Popen(args)
+        p.wait()
+
+        returnCode = p.returncode
+
+        if (returnCode == 0):
+            success = True
+        else:
+            print "Subproccess terminates with %s. This is an error"\
+                       % returnCode
+    except OSError, err:
+        success = False
+
+    return success
+
+try:
+    #Read parameters from dialog
+    inputMXD = arcpy.GetParameterAsText(0)
+    outputMXD = arcpy.GetParameterAsText(1)
+    template = arcpy.GetParameterAsText(2)
+
+    print "InputMXD: %s,\nOutputMXD: %s" % (inputMXD, outputMXD)
+
+    # execute Java-command for converting
+    javacmd = "-Dmapserver.library.name=lib/mapscript -jar mxd-testbed_sh.jar"
+    javafiles = "-mxd %s -map %s -template %s " % (inputMXD, outputMXD, template)
+
+    cmd = "java "+ javafiles + javacmd
+    print cmd
+    executeCommand(cmd)
+    
+except Exception, e:
+  import traceback
+  map(arcpy.AddError, traceback.format_exc().split("\n"))
+  arcpy.AddError(str(e))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)