Solved! Go to Solution.
#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
import arcpy, os, sys
#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
dir = arcpy.GetParameterAsText(1)
fc_path = arcpy.GetParameterAsText(2)
for mapDoc in mxdList:
arcpy.mapping.MapDocument(mapDoc)
for lyr in m.ListLayers(mxd):
if lyr.supports('DATASOURCE'):
if lyr.dataSource == fc_path:
max_list = []
rows = arcpy.SearchCursor(fc_path, "Sheet_ID")
for row in rows:
max_list.append(row.Sheet_ID)
pdf_count = max(max_list)
arcpy.AddMessage('Sheet count: %s'%pdf_count)
else:
arcpy.AddError('No layers in %s match data source'%mapDoc)
pdfDoc = arcpy.mapping.PDFDocumentOpen(path) print pdfDoc.pageCount
The pdfs are created from the one mxd. For example: Abilene has 11 sheets (data driven pages) so when that tool makes the PDFs it makes 11 PDFS. One for each sheet or Data driven page.
#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
import arcpy, os, sys
from os import path as p
from arcpy import mapping as m
#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = arcpy.GetParameterAsText(0).split(';')
pdf_path = arcpy.GetParameterAsText(1)
fc_path = arcpy.GetParameterAsText(2)
report = {}
for mapDoc in mxdList:
arcpy.mapping.MapDocument(mapDoc)
for lyr in m.ListLayers(mxd):
if lyr.supports('DATASOURCE'):
if lyr.dataSource == fc_path:
max_list = []
rows = arcpy.SearchCursor(fc_path, "Sheet_ID")
for row in rows:
max_list.append(row.Sheet_ID)
pdf_count = max(max_list)
arcpy.AddMessage('Sheet count: %s'%pdf_count)
else:
arcpy.AddError('No layers in %s match data source'%mapDoc)
# List all PDF's in the pdf_path folder
arcpy.env.workspace = ws = pdf_path
for pdf_doc in arcpy.ListFiles('*.pdf'):
if ''.join([a for a in pdf_doc.split('.')[0] if a.isalpha()]) == mapDoc.replace('_',''):
pdf = p.join(ws, pdf_doc)
pdf_object = arcpy.mapping.PDFDocumentOpen(pdf)
page_count = pdf_object.pageCount
if page_count == pdf_count:
arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc))
else:
report[mapDoc] = pdf_doc
# Report maps that do not match up
if len(report > 0):
f = open(p.join(ws,'Page_Report.txt'))
for k,v in report.iteritems():
f.write('%s Sheet Count does not match number of pages in %s\n\n' %(k,v))
f.close()
arcpy.AddMessage('Created report for map documents and PDF\'s')
else:
arcpy.AddMessage('All PDF\'s have the correct amount of pages')
#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
import arcpy, os, sys
from os import path as p
from arcpy import mapping as m
#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = arcpy.GetParameterAsText(0).split(';')
pdf_path = arcpy.GetParameterAsText(1)
fc_path = arcpy.GetParameterAsText(2)
report = {}
page_list = []
for mapDoc in mxdList:
arcpy.mapping.MapDocument(mapDoc)
for lyr in m.ListLayers(mxd):
if lyr.supports('DATASOURCE'):
if lyr.dataSource == fc_path:
max_list = []
rows = arcpy.SearchCursor(fc_path, "Sheet_ID")
for row in rows:
max_list.append(row.Sheet_ID)
sheet_count = max(max_list)
arcpy.AddMessage('Sheet count: {0}'.format(sheet_count))
else:
arcpy.AddError('No layers in %s match data source'%mapDoc)
# List all PDF's in the pdf_path folder
arcpy.env.workspace = ws = pdf_path
for pdf_doc in arcpy.ListFiles('%s*.pdf' %mapDoc):
page_list.append(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))
page_count = max(page_list)
if page_count == sheet_count:
arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc))
else:
report[mapDoc] = pdf_doc
# Report maps that do not match up
if len(report > 0):
f = open(p.join(ws,'Page_Report.txt'))
for k,v in report.iteritems():
f.write('%s Sheet Count does not match number of pages in %s\n\n' %(k,v))
f.close()
arcpy.AddMessage('Created report for map documents and PDF\'s')
else:
arcpy.AddMessage('All PDF\'s have the correct amount of pages')
#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
import arcpy, os, sys
from os import path as p
from arcpy import mapping as m
#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = arcpy.GetParameterAsText(0).split(';')
pdf_path = arcpy.GetParameterAsText(1)
fc_path = arcpy.GetParameterAsText(2)
report = {}
page_list = []
for mapDoc in mxdList:
arcpy.AddMessage(mapDoc)
mxd = arcpy.mapping.MapDocument(mapDoc)
for lyr in m.ListLayers(mxd):
if lyr.supports('DATASOURCE'):
if lyr.dataSource == fc_path:
max_list = []
rows = arcpy.SearchCursor(lyr)
for row in rows:
max_list.append(row.Sheet_ID)
sheet_count = max(max_list)
arcpy.AddMessage('Sheet count: %s'%sheet_count)
else:
arcpy.AddError('No layers in %s match data source'%mapDoc)
# List all PDF's in the pdf_path folder
arcpy.env.workspace = ws = pdf_path
for pdf_doc in arcpy.ListFiles('*.pdf'):
page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()])))
page_count = max(page_list)
if page_count == sheet_count:
arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc))
else:
report[mapDoc] = pdf_doc
# Report maps that do not match up
if len(report) > 0:
f = open(p.join(ws,'Page_Report.txt'))
for k,v in report.iteritems():
f.write('%s Sheet Count does not match number of pages in %s\n\n' %(k,v))
f.close()
arcpy.AddMessage('Created report for map documents and PDF\'s')
else:
arcpy.AddMessage('All PDF\'s have the correct amount of pages')