POST
|
I'm trying to create a tool where the user can specify multiple MXD-files, which will be exported to a specified output folder. As an option, the user can set the resolution for the PDF's. My code seems to work ok, up to the point where I want to add the resolution parameter. import arcpy, os, sys, string
# Define parameter settings for the toolbox
def getParameterInfo(self):
#Define parameter definitions
# First parameter
param0 = arcpy.Parameter(
displayName="Input MXD's",
name="multimxds",
datatype="DEMapDocument",
parameterType="Required",
direction="Input",
multiValue=True)
# Second parameter
param1 = arcpy.Parameter(
displayName="Output folder",
name="outputfolder",
datatype="DEFolder",
parameterType="Required",
direction="Output")
# Third parameter
param2 = arcpy.Parameter(
displayName="PDF Resolution",
name="pdfREs",
datatype="GPLong",
parameterType="Required",
direction="Input")
#overwirte existing PDFs
arcpy.env.overwriteOutput = 1
multimxds = [filename for filename in string.split(arcpy.GetParameterAsText(0), ";")]
outputfolder = arcpy.GetParameterAsText(1)
pdfREs = arcpy.GetParameterAsText(2)
pdfRES = str(pdfREs)
teller = 0 # to be used for generating pdf file names when no mxd.title is specified
#print multimxds
#Create output folder
if not os.path.exists(outputfolder): os.makedirs(outputfolder)
#trying to set folder path
folderpath = outputfolder
#export to pdf
#trying to export to pdf using title name and folder parameter
try:
for mxdloop in multimxds:
mxd = arcpy.mapping.MapDocument(mxdloop)
if mxd.title != "":
name = mxd.title
else:
name = str(teller)
pdf = folderpath + '\\' + name + ".pdf"
if os.path.exists(pdf) == 'true':
pdf = folderpath + '\\' + name + str(teller) + ".pdf"
else: pdf = pdf
print pdf # for debugging
arcpy.mapping.ExportToPDF(mxd, pdf, data_frame="PAGE_LAYOUT", df_export_width="", df_export_height="", resolution=pdfRES)
teller = teller+1
del mxd
arcpy.AddMessage(pdf + "has been exported succesfully")
print teller # for debugging
except Exception as e:
print e.message
# If using this code within a script tool, AddError can be used to return messages
# back to a script tool. If not, AddError will have no effect.
arcpy.AddError(e.message)
#Succes message in the end
arcpy.AddMessage("Done exporting "+str(teller)+ " MXD's to PDF's in folder" + folderpath)
#delete folderpath variable
del folderpath The code is largely based on snippets from other and the ESRI help. What puzzles me, is that I can't find out what is the cause for this error: "PageLayoutObject: Error in parsing arguments for ExportToPDF". Any suggestions, other than "It's Friday, go home"?
... View more
03-29-2013
08:33 AM
|
0
|
3
|
3105
|
POST
|
Dear Jason, I tried your first code, and am getting the Invalid MXD name error as well. When I added a print command to multimxds, it showed me that the name had chaged to *.mx, e.g. the letter D is missing from the extension. I think that is coming from this bit: multimxds = [filename[1:-1] Although I am not very experienced with arcpy yet. I hope it helps
... View more
03-28-2013
01:23 AM
|
0
|
0
|
268
|
Online Status |
Offline
|
Date Last Visited |
07-14-2023
11:14 AM
|