ArcGIS Python Map Book PDF not working blank PDF

The purpose of the code is to make a PDF map book that displays all of the large lakes in North America. I'm trying to run this code to make a map book but it gives me a blank PDF. How can I fix this?

## Import arcpy module
import arcpy
import math
import os
from arcpy import env
arcpy.env.overwriteOutput = True

# Define inputs and outputs - Script arguments

arcpy.env.workspace = r"F:\Geog173\Lab7\Lab7_Data"

Lakes = "NA_Big_Lakes.shp"
Cities = "NA_Cities.shp"
NA = "North_America.shp"


##Python arguments
## Arguments = NA_Big_Lakes.shp NA_Cities.shp New_Lakes.shp  Center_Lakes.shp 
Lakes= 'NA_Big_Lakes.shp'
NA = 'North_America.shp'
Cities = 'NA_Cities.shp'
##New_Lakes = 'New_Lakes.shp'
##Center_Lakes = 'Center_Lakes.shp'

# Identify the geometry field
desc = arcpy.Describe(Lakes)
shapeName = desc.ShapeFieldName

# Identify the geometry field in Cities shapefile
##desc = arcpy.Describe(Cities)
##shapefieldnameCity = desc.ShapeFieldName

#Get lake cursor
inrows = arcpy.SearchCursor(Lakes)

# Set up variables for output path and PDF file name
outDir = r"F:\Geog173\Lab7\Lab7_Data"
finalMapPDF_filename = outDir + r"\NA_Big_Lake_Mapbook.pdf"


# Check whether the mapbook PDF exists. If it does, delete it.
if os.path.exists(finalMapPDF_filename):
    os.remove(finalMapPDF_filename)

# Create map book PDF
finalMapPDF = arcpy.mapping.PDFDocumentCreate(finalMapPDF_filename)

# Create MapDocument object pointing to specified mxd
mxd = arcpy.mapping.MapDocument(outDir + r"\OriginalMap.mxd")

# Get dataframe
df = arcpy.mapping.ListDataFrames(mxd)[0]

# ----------------------------------------------------------------------------#
# Start appending pages. Title page first.
# ----------------------------------------------------------------------------#
# Find text element with value "test", and replace it with other value
mapText = "A Map Book for North American Large Lakes " + '\n\r' + "Kishore, A., Geog173, Geography, UCLA" +  '\n\r' + " Lake number: 18" +  '\n\r' + " Total area: 362117 km2" +  '\n\r' + " Mean area: 20118 km2"
print mapText
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.text == "test":
        elm.text = mapText

arcpy.RefreshTOC()
arcpy.RefreshActiveView()

#df.extent = feature.extent
arcpy.mapping.ExportToPDF(mxd, outDir + r"\TempMapPages.pdf")

# Append multi-page PDF to finalMapPDF
finalMapPDF.appendPages(outDir + r"\TempMapPages.pdf")

#initialize text value, so it can be reused in next iteration
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.text == mapText:
        elm.text = "test"


# ----------------------------------------------------------------------------#
# Loop through each lake
# ----------------------------------------------------------------------------#

# Loop through each row/feature
lakecount = 0
for row in inrows:
    lakecount = lakecount + 1
    CITY_NAME = ""
    CNTRY_NAME = ""
    ADMIN_NAME = ""
    POP_CLASS = ""
    DISTANCE = 0
    XY = ""
    #print "shapeName" , shapeName
    # Create the geometry object
    feature = row.getValue(shapeName)
    mapText = "Lake FID: " + str(row.FID) +  ", Area (km2): " + str(row.Area_km2)
    print mapText

    # Find text element with value "test", and replace it with other value
    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if elm.text == "test":
            elm.text = mapText


    arcpy.RefreshTOC()
    arcpy.RefreshActiveView()

    df.extent = feature.extent
    arcpy.mapping.ExportToPDF(mxd, outDir + r"\TempMapPages.pdf")

    # Append multi-page PDF to finalMapPDF
    finalMapPDF.appendPages(outDir + r"\TempMapPages.pdf")


# Set up properties for Adobe Reader and save PDF.
finalMapPDF.updateDocProperties(pdf_open_view = "USE_THUMBS",
                             pdf_layout = "SINGLE_PAGE")       

finalMapPDF.saveAndClose()


# Done. Clean up and let user know the process has finished.
del row, inrows
del mxd, finalMapPDF
print "Map book for lakes in North America is complete!"

Answers


First off you should remove the last lines of your code where you delete the mxd. Run the code again and inspect the MXD. Are the data layers drawing properly? I recommend having code that completely works before performing file cleanup so you can identify potential errors.


Need Your Help

struts generating form elements from bean

java jsp struts struts-1

I have a Struts 1.2 Bean and a Bean code as below in JSP Page

Authentication Protocol in Freeradius

authentication protocols freeradius

I want to setup a radius server for my college of around 2000 students and a hundred faculties. I am familiar with freeradius+MySQL but never deployed it except for in on my laptop.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.