1

New to Python.

I have an mxd file file with three layers and one is a layer of elementary school boundaries.

Goal: Make a pdf doc with a page for each elementary boundary.

  1. arcpy.SelectLayerByAttribute_management(Counties, "NEW_SELECTION", "Boundary = 'PineCone'")
  2. ExportToPDF
  3. Next boundary polygon
  4. Append PDF
  5. Save

My question: Do I need to make a physical file of the elementary boundary layer before I can “SelectLayerByAttribute” for each boundary? Or is there a way to loop through the boundaries by making the selections straight from the mxd file.Below is not complete code, just the thought process.

import arcpy
from arcpy.mapping import *
mapDoc = MapDocument(r"C:temp\boundary.mxd")
pdfElementary = r”C:\Temp\Elem_Bndries”

???
???

for bname in boundaryList
arcpy.SelectLayerByAttribute_management(Counties, "NEW_SELECTION", "boundary = bname")
ExportToPDF (mapDoc, pdfElementary, "PAGE_LAYOUT") 
pdfFinalBoundary  = appendPages(pdfElementary)

pdfFinalBoundary .saveAndClose () 
del pdfFinalBoundary 

2 Answers 2

2

You can use the below code in the python window to automate the pdf export for data driven pages:

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  pageName=mxd.dataDrivenPages.pageRow.SCHOOLNAME
  arcpy.mapping.ExportTOPDF(mxd, "C:\Temp" + str(pageName) + ".png")
del mxd

Other options:

ExportTOTIFF

1

To "Make a pdf doc with a page for each elementary boundary" I would recommend an alternative approach of using your layer of elementary boundaries as the index for Data Driven Pages:

Data Driven Pages allow you to quickly and easily create a series of layout pages from a single map document. A feature layer, or index layer, divides the map into sections based on each index feature in the layer and generates one page per index feature.

With a map enabled for Data Driven Pages then you can just Export Map to a multi-page PDF file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.