Sharing with Python since this is more of Python and scripting question than a mapping question.
Your code was/is all strung together. I took a stab at formatting it using the Syntax highlighter. Is what I have below correct? If not, please update your code snippet
# Import all the libraries
import arcpyfrom arcpy.mapping
# Set up variables;
countiesPath = "C:\\Data\\COUNTIES.shp"
pdfPath = "C:\\Data\\Counties.pdf"
mxdPath = "C:\\Data\\Counties.mxd"
#Add a pointer to the counties layer in the data frame
dataFrame = ("COUNTIES")
#Create the master pdf
finalPDF = PDFDocumentCreate("C:\\Data\\CountiesMapbook.pdf")
#Set up cursor for counties (need county name)
#Set up a loop to loop through counties
# build the where clause
# select layer by attribute - create a new selection
# zoom to selelction - set the data frame extent to the getSelectedExtent() of the county layer
dataFrame.extent = countyLyr.getSelectedExtent()
# zoom out a bit using the sacale property of the data frame
# use title property of the map document to change the title of the page
# export the current map to pdf
# append the pdf to the master pdf
finalPDFDoc.append (<temp PDF name is>)
#delete the map document object, pdf
This is what the Data Driven Pages toolbar and tool is designed to do. Enable Data Driven Pages, choose your counties layer, check your layout, and then export to PDF, choosing a single page or a page range.
I work with Data Driven Pages quite a bit and understand how they work. However, what I'm looking for here; is assistance/guidance with Python, Arcpy and working with an .mxd, it's linked data layers and creating a mapbook without any previously setup Data Driven Pages.
Data Driven Pages are powerful, but do not always allow the degree of customization needed for a map automation project. Here is an example of python code we use to automatically generate scores of customized maps within minutes into separate PDF with unique names based on the map layer attributes you select:
Hello, I am trying to do the exact same thing this code is doing. but with arcpy.mp so that it can be done in ArcGIS Pro. I am struggling with some of the new syntax of arcpy.mp compared to arcpy.mapping. Does anyone know how to do this or point me in the direction with documentation on how to create individual PDF's for features in a feature class?