Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

PageLayoutObject: Error in parsing arguments for ExportToPDF

$
0
0
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.

Code:

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"?

Viewing all articles
Browse latest Browse all 2485

Trending Articles