Mercurial > mxd2map
view contrib/python/foobar.py @ 299:c4fb04f6422f
Write GROUP into grouped maps
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 05 Sep 2012 16:13:39 +0200 |
parents | 93699e8f2d1f |
children |
line wrap: on
line source
# 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))