Mercurial > mxd2map
comparison contrib/python/foobar.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 |
comparison
equal
deleted
inserted
replaced
113:0db6eacad0e6 | 114:93699e8f2d1f |
---|---|
1 # Author: ESRI | |
2 # Date: July 5, 2010 | |
3 # Version: ArcGIS 10.0 | |
4 # Summary: This script will add a layer file into a map document. The script | |
5 # must be run from within ArcMap because it references the CURRENT | |
6 # map document. The purpose of the script is to create a user | |
7 # friendly tool that allows users to simply add a layer from a list | |
8 # of existing layer files all stored in a common location. A validation | |
9 # script is used to automatically populate two of the parameters. | |
10 # The parameters are: | |
11 # 1) Browse to a folder that contains layer files. This could be | |
12 # hard coded within the validation script eliminating the need | |
13 # for entering this parameter. | |
14 # 2) Select a layer file from the list. This is auto populated | |
15 # using a validation script. | |
16 # 3) Select a data frame. This is also auto populated using a | |
17 # validation script. | |
18 # 4) Select one of 3 placement positions. | |
19 # | |
20 # Note: This script tool will only work if background processing is disabled. | |
21 # because CURRENT is being used. | |
22 # Note: To run the script from ArcMap either run the script tool from the | |
23 # Catalog window from within ArcMap or add the script tool into the UI | |
24 # via the customize dialog box [Geoprocessing Tools]. | |
25 | |
26 import arcpy | |
27 import shlex, subprocess | |
28 | |
29 #Helper for executing an external shell-scrip or programm | |
30 def executeCommand(command): | |
31 success = False | |
32 try: | |
33 args = shlex.split(command) | |
34 p = subprocess.Popen(args) | |
35 p.wait() | |
36 | |
37 returnCode = p.returncode | |
38 | |
39 if (returnCode == 0): | |
40 success = True | |
41 else: | |
42 print "Subproccess terminates with %s. This is an error"\ | |
43 % returnCode | |
44 except OSError, err: | |
45 success = False | |
46 | |
47 return success | |
48 | |
49 try: | |
50 #Read parameters from dialog | |
51 inputMXD = arcpy.GetParameterAsText(0) | |
52 outputMXD = arcpy.GetParameterAsText(1) | |
53 template = arcpy.GetParameterAsText(2) | |
54 | |
55 print "InputMXD: %s,\nOutputMXD: %s" % (inputMXD, outputMXD) | |
56 | |
57 # execute Java-command for converting | |
58 javacmd = "-Dmapserver.library.name=lib/mapscript -jar mxd-testbed_sh.jar" | |
59 javafiles = "-mxd %s -map %s -template %s " % (inputMXD, outputMXD, template) | |
60 | |
61 cmd = "java "+ javafiles + javacmd | |
62 print cmd | |
63 executeCommand(cmd) | |
64 | |
65 except Exception, e: | |
66 import traceback | |
67 map(arcpy.AddError, traceback.format_exc().split("\n")) | |
68 arcpy.AddError(str(e)) |