Select to view content in your preferred language

Set output extent in multiple MXD exporter script

298
0
09-23-2020 09:19 AM
DanMichaelan
New Contributor

Hello GeoNet! Lately I started using the very useful Multiple MXD exporter tool, a community tool based on a python script. I wonder, is it possible to add to the code to make it alter the different extents of all the MXDs to a single fixed one in my output maps, to a custom one of my choice? I tried playing with the loop in the code adding to it some ideas I found on the internet, based on arcpy. I had no success so far.

I will be very grateful for any help.

Below is the Python script of the tool, written by Vijay Paul. I removed some parts that are irrelevant. Full code available in the link above.

import arcpy, os, string
from arcpy import env
overwriteOutput = True
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
dest = arcpy.GetParameterAsText(1)
DPI = arcpy.GetParameterAsText(2)
ext = arcpy.GetParameterAsText(3)
appendPDF = arcpy.GetParameterAsText(4)

#PNG
if (ext == "PNG"):
ext = ".png"
for mxdType in mxdList:
(workspace, filename) = os.path.split(mxdType)
fullpath = os.path.join(workspace, filename)
#need to remove single quoatation
fullstring = fullpath.replace("'","")
if os.path.isfile(fullstring):
basename, extension = os.path.splitext(fullstring)
if extension.lower() == ".mxd":
mxd = arcpy.mapping.MapDocument(fullstring)
pngnum = os.path.basename(fullstring)
arcpy.AddMessage("Exporting Map Document:" + pngnum)
PNG = dest + "\\" + pngnum.replace(".mxd", ext)
arcpy.mapping.ExportToPNG(mxd,PNG,resolution=DPI)

if appendPDF == "true":
arcpy.AddMessage(appendPDF)
arcpy.AddMessage("Combining PDF documents")
arcpy.AddMessage(filenameList)
appendName = dest + "\\" + "merge.pdf"
pdfDoc = arcpy.mapping.PDFDocumentCreate(appendName)
for page in filenameList:
pagePath = dest + "\\" + page
pdfDoc.appendPages(pagePath)
pdfDoc.saveAndClose()

#delete variable references
del mxd
del mxdList
del PNG
del dest
del ext

Tags (3)
0 Kudos
0 Replies