Select to view content in your preferred language

Almost there, but I need help finding a bug

2859
10
07-16-2013 04:04 PM
TomMagdaleno
Regular Contributor
Hi all,
  I'm having a problem with my code.  It creates data driven pages from two seperate MXDs as left and right side page PDFs.  Then it puts them together into one PDF.   It used to work on my Windows XP machine and ArcGIS 10.0 but is giving me trouble on my new Windows 7 machine with ArcGIS 10.1.  The code is below.  Most is commented out because the failure happens when it tries to combine the two sets of pdfs.  Any ideas?


import arcpy, os

# Create an output directory variable
#
outDir = r"C:\Working_Directory\Combined"  

# Create a new, empty pdf document in the specified output directory
#
finalpdf_filename = outDir + r"\FinalStorm.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"G:\CamarilloGIS\Projects\Atlases\Storm_Drain\2007\CoverSheet.pdf")

# Add the index map to the pdf
#
#  finalPdf.appendPages(r"G:\CamarilloGIS\Projects\Atlases\Storm_Drain\2007\GridIndex.pdf")

# Create Facing Pages for the map book
# Create pages for left-hand side of the book
#
mxdPathLeft = r"G:\CamarilloGIS\Projects\PublicWorks\STORMWATER\Updates\Even11x17_Aerial.mxd"
tempMapLeft = arcpy.mapping.MapDocument(mxdPathLeft)
tempDDPLeft = tempMapLeft.dataDrivenPages

# Loop creates individual pdf's for odd numbered pages
#
#for pgNumLeft in range(1, tempDDPLeft.pageCount + 1,):
#  temp_filename = r"C:\Working_Directory\L_" + \
#                            str(pgNumLeft) + ".pdf"
#  if os.path.exists(temp_filename):
#    os.remove(temp_filename)
#  tempDDPLeft.exportToPDF(temp_filename, "RANGE", pgNumLeft)
#
# Create pages for right-hand side of the book
#
mxdPathRight = r"G:\CamarilloGIS\Projects\PublicWorks\STORMWATER\Updates\Odd11x17_Aerial.mxd"
tempMapRight = arcpy.mapping.MapDocument(mxdPathRight)
tempDDPRight = tempMapRight.dataDrivenPages

# Loop creates individual pdf's for even numbered pages
#
#for pgNumRight in range(2, tempDDPRight.pageCount + 1,):
#  temp_filename = r"C:\Working_Directory\R_" + \
#                             str(pgNumRight) + ".pdf"
#  if os.path.exists(temp_filename):
#    os.remove(temp_filename)
#  tempDDPRight.exportToPDF(temp_filename, "RANGE", pgNumRight)

# Append right and left-hand pages together in proper order
i = 1 #set i equal to 1 to start with the first PDFs
for pgNum in range(1, tempDDPLeft.pageCount + 1):
  print "Page", pgNum, "of", tempDDPLeft.pageCount
  tempPDF = r"C:\Working_Directory\combined" + os.sep + str(pgNum) + ".pdf"
  finalPdf.appendPages(r"C:\Working_Directory\L_" + str(i) + ".pdf") #appends the first PDF from the odds
  finalPdf.appendPages(r"C:\Working_Directory\R_" + str(i) + ".pdf") #appends the first PDF from the evens
  i = i + 1 #adds 1 to i so that it will append PDFs number 2 next, then 3, 4, and so on through 48finalPdf.appendPages(tempPDF)
# 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, mxdPathLeft, mxdPathRight, tempDDPLeft, tempDDPRight, 
tempMapLeft, tempMapRight, tempPDF


Here is the error...

Page 1 of 68

Traceback (most recent call last):
  File "C:\Working_Directory\PythonCombine - Copy.py", line 59, in <module>
    finalPdf.appendPages(r"C:\Working_Directory\R_" + str(i) + ".pdf") #appends the first PDF from the evens
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", line 960, in appendPages
    return convertArcObjectToPythonObject(self._arc_object.appendPages(*gp_fixargs((pdf_path, password_for_pdf), True)))
AttributeError: Invalid path
>>>


I've checked the paths to the the .py file and the pages and the _mapping.py.  But I suspect their is something wrong with _mapping.py
__
Tags (2)
0 Kudos
10 Replies
RebeccaStrauch__GISP
MVP Emeritus

Then you would think it would be correct, unless it changed between 10.1 and 10.2.​  Hard to say without doing a lot more digging....which, since you got it working, just worth noting I guess.

0 Kudos