Select to view content in your preferred language

Arcpy Error Message

2642
2
Jump to solution
11-07-2013 12:40 PM
BrianHovis
Frequent Contributor
I am very new to arcpy and am trying to duplicate code from an exampe in ArcGIS 10.2 Desktop Help called "Inserting supporting pages into your map book."  I keep get error messages (mostly refer to line 10), including the one at the bottom of this message.  Any help would be appreciated.  I may be asking too much, because you can't see my file locations.

>>> import arcpy, os
...
... # Create an output location variable
... outDir = r"C:\temp\final_output" 
...  
... # Create a new, empty pdf document in the specified output location folder
... finalpdf_filename = outDir + r"\ArenacMB.pdf"
... if os.path.exists(finalpdf_filename):
...   os.remove(finalpdf_filename)
... finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)
...
... # Add the title page to the pdf
... finalPdf.appendPages(r"C:\temp\TITLE.pdf")
...
... # Add the overview map to the pdf
... finalPdf.appendPages(r"C:\temp\AdvancedExport.pdf")
...
... # Export the Data Driven Pages to a temporary pdf and then add it to the
... # final pdf. Alternately, if your Data Driven Pages have already been
... # exported, simply append that document to the final pdf.
... #
... mxdPath = r"C:\temp\MBExample\maps\ArenacDDP Reports.mxd"
... tempMap = arcpy.mapping.MapDocument(mxdPath)
... tempDDP = tempMap.dataDrivenPages
... temp_filename = r"C:\temp\tempDDP.pdf"
... finalPdf.appendPages(temp_filename)
...
...
... # Update the properties of the final pdf
... finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",
...                              pdf_layout="SINGLE_PAGE")
...
... # Save your result
... finalPdf.saveAndClose()
...
... # Delete variables
... del finalPdf
...
Runtime error
Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1679, in PDFDocumentCreate
    return PDFDocument(pdf_path)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\arcobjects\_base.py", line 47, in __init__
    for arg in args))
AttributeError: Invalid path
>>>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Esri Alum
Does the folder C:\temp\final_output exist? Try this in your code just in case:

# Create a new, empty pdf document in the specified output location folder if not os.path.isdir(outDir):   arcpy.AddMessage("{} did not exist; creating...".format(outDir))   os.makedirs(outDir) finalpdf_filename = outDir + r"\ArenacMB.pdf" if os.path.exists(finalpdf_filename):   os.remove(finalpdf_filename) finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)


if C:\temp\final_output does exist, you may not have permission to write to it.

View solution in original post

0 Kudos
2 Replies
JasonScheirer
Esri Alum
Does the folder C:\temp\final_output exist? Try this in your code just in case:

# Create a new, empty pdf document in the specified output location folder if not os.path.isdir(outDir):   arcpy.AddMessage("{} did not exist; creating...".format(outDir))   os.makedirs(outDir) finalpdf_filename = outDir + r"\ArenacMB.pdf" if os.path.exists(finalpdf_filename):   os.remove(finalpdf_filename) finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)


if C:\temp\final_output does exist, you may not have permission to write to it.
0 Kudos
BrianHovis
Frequent Contributor
Thanks so much for taking a look at the code.  Your suggestion led me to find the mistake in code.  Much appreciated.
0 Kudos